Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom type translators #165

Open
backfromexile opened this issue Feb 5, 2024 · 1 comment
Open

Add support for custom type translators #165

backfromexile opened this issue Feb 5, 2024 · 1 comment

Comments

@backfromexile
Copy link
Contributor

backfromexile commented Feb 5, 2024

Tapper does not consider custom type mappers for types.
This makes it impossible to map types that cannot be marked as [TranspilationSource], for example types that have been defined in an external package (also related to #133).

Tapper should fetch custom ITypeTranslators from the transpiled project file.
For this, we probably need another attribute to mark type mappers as mappers for specific types.
Proposal: [TypeTranslator(params Type[] sourceTypes)]

This should work with normal types, and generic types (e.g. Optional<T>) as well as concrete generic types (e.g. Optional<string>).

#164 already adds the foundation for generic type transliation, but support for concrete generic type translation is still missing here.

After this has been implemented, it should be fairly easy to define the TypeTranslator attribute.

@backfromexile backfromexile changed the title Add support for custom type mappers Add support for custom type translators Feb 7, 2024
@backfromexile
Copy link
Contributor Author

After thinking about this and experimenting a bit, I think it's best we support two scenarios:

  1. Support custom type converters (similar to a type translator, but only for the actual type definition without the export type MyType = ). These should be used to transpile the type definitions inside the default ITypeTranslator. Imo, these should work for all types, not just the ones marked with [TranspilationSource] to support custom type converters for external types.
  2. Support custom type mappers like the ones for collection and dictionary types.

However, I think 2 isn't really necessary if we support generic type translation and support custom type converters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant