You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my team's project, we prefer to map all DateTime and DateTimeOffset C# types to a Moment TypeScript type. Using this type requires an additional import from the moment package.
I found that I am able to do this for individual fields using a GenerationSpec:
public class DemoGenerationSpec : GenerationSpec
{
public override void OnBeforeGeneration(OnBeforeGenerationArgs args)
{
this.AddInterface<UserDetailed>()
.Member(t => nameof(t.CreatedOn))
.Type("Moment", "moment");
}
}
Or using an annotation:
public class UserDetailed
{
[TsType("Moment", "moment")]
public required DateTimeOffset CreatedOn { get; set; }
// Trimmed for brevity
}
But I can't find a way to setup a universal type mapping rule which will affect all usage of a type. Does such a method exist?
Issue #175 seems to touch on this a bit noting that the CustomTypeMappings option could be changed from a IDictionary<string, string> to some kind of object allowing additional configuration. Maybe this would be a good use case for that restructuring?
The text was updated successfully, but these errors were encountered:
In the meantime, config can be used to map the type, and also inject its import to all generated files:
{
"customTypeMappings": {
"Some.Custom.Type": "SCT"
},
"fileHeading": "/** This is an auto-generated file */\r\n\r\nimport { SCT } from \"somewhere\";\r\n"
}
The downside is of course that it will be added to ALL generated files, even the ones that don't need it. But /* eslint-disable */ could also be injected to supress warnings.
In my team's project, we prefer to map all
DateTime
andDateTimeOffset
C# types to aMoment
TypeScript type. Using this type requires an additional import from themoment
package.I found that I am able to do this for individual fields using a
GenerationSpec
:Or using an annotation:
But I can't find a way to setup a universal type mapping rule which will affect all usage of a type. Does such a method exist?
Issue #175 seems to touch on this a bit noting that the
CustomTypeMappings
option could be changed from aIDictionary<string, string>
to some kind of object allowing additional configuration. Maybe this would be a good use case for that restructuring?The text was updated successfully, but these errors were encountered: