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

allow configuring the type used for a C# class #158

Closed
wants to merge 1 commit into from

Conversation

hahn-kev
Copy link

@hahn-kev hahn-kev commented Jan 29, 2024

this allows specifying the type for a class via the TranspilationSourceAttribute. Relates to #133

Example:

[TranspilationSource(TypescriptType = "{color: 'blue'|'red'}")]
public class AttributeAnnotatedClass5
{
    public string Color { get; init; }
}

becomes this:

type AttributeAnnotatedClass5 = {color: 'blue'|'red'}

This only works at the class level, not the field level. Doing this at the field level would require some more work and I didn't need it.

@hahn-kev hahn-kev changed the title allow configuring the type used for a C# class. Related to #133 allow configuring the type used for a C# class Jan 29, 2024
@backfromexile
Copy link
Contributor

I'm not in favor of this change.

Is there a reason you cannot define an enum for the Color property and instead must resort to this?

@hahn-kev
Copy link
Author

hahn-kev commented Feb 7, 2024

because that's not my actual use case. My actual use case is that I have a struct that is just a wrapper around a string with validation around it on the server side. There are converters in place so when it's serialized and deserialized it's just treated as a string. So I want to just tell Tapper to treat my struct as a string. Here's an example

public struct WsId {
    public string Value {get;set;}
}

expected TS type

type WsId = string;

this totally works, but right now after I run the type generator I have to rewrite the type from:
type WsId = {Value: string} into type WsId = string

that said any class could have a custom json converter and there's no way the code generator could determine what the type should be for a class with a custom converter. So it would be nice if there was an escape hatch to override the type that's generated.

@nenoNaninu
Copy link
Owner

After consideration, it was determined that Tapper does not need this feature.

@nenoNaninu nenoNaninu closed this Apr 20, 2024
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

Successfully merging this pull request may close these issues.

3 participants