Flowtypes generation is removedEnableExplicitNullabilityoption is replaced withNullabilityMode.NoneoptionEnumGenerationModeandPluralizeoptions are removedNullabilityModehas flags, which means that combinations such asPessimistic | NullableReferencecan be used
All reflection types used in TypeScript generation (e.g. Type, PropertyInfo), were replaced by new abstractions.
The main abstraction is ITypeInfo which besides Type information also has nullability information and info about property/method that has this specific type.
ITypeInfo has Reflection and Roslyn implementation.
It also has equality methods and can be constructed from Reflection type by calling TypeInfo.From<T>().
To migrate custom generation code to new version, you should first replace all occurrences of these types:
Type→ITypeInfoPropertyInfo→IPropertyInfoMethodInfo→IMethodInfoParameterInfo→IParameterInfoFieldInfo→IFieldInfoICustomAttributeProvider→IAttributeProvidertypeof(T)→TypeInfo.From<T>()orTypeInfo.From(typeof(T))type == typeof(T)→type.Equals(TypeInfo.From<T>())
-
Generated type nullability is determined in
ReferenceFrommethod. In most cases it is better to inherit fromTypeBuildingContextBaseand implementReferenceFromInternalmethod to avoid dealing with nullability issues. -
Parameter
customAttributeProviderwas removed fromReferenceFrommethod.IAttributeProvidercan be accessed usingtype.Memberproperty.
public interface ITypeBuildingContext
{
- TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator, ICustomAttributeProvider customAttributeProvider);
+ TypeScriptType ReferenceFrom(ITypeInfo type, TypeScriptUnit targetUnit, ITypeGenerator typeGenerator);
}BuildAndImportTypeis now an extension method forITypeGenerator,customAttributeProviderparameter was also removed.
public interface ITypeGenerator
{
- TypeScriptType BuildAndImportType(TypeScriptUnit targetUnit, ICustomAttributeProvider? customAttributeProvider, Type type);
}
public static class TypeScriptGeneratorHelpers
{
+ public static TypeScriptType BuildAndImportType(this ITypeGenerator typeGenerator, TypeScriptUnit typeScriptUnit, ITypeInfo type)
+ {
+ return typeGenerator.ResolveType(type).ReferenceFrom(type, typeScriptUnit, typeGenerator);
+ }
}When using Roslyn to generate TypeScript, Customization code is preprocessed, replacing TypeInfo.From<T>() and TypeInfo.From(typeof(T)) invocations with RoslynTypeInfo instances and then compiled to in-memory assembly. Therefore, several changes to customization code are required to use Roslyn:
- There should be no
typeof(T)invocations not wrapped withTypeInfo.From() - All customization-related code should be in the same namespace
- Customization-related code should not depend on any third party packages