Class TsTypeAlias
- Namespace
- TypedRest.CodeGeneration.TypeScript.Model
- Assembly
- TypedRest.CodeGeneration.TypeScript.dll
A TypeScript type alias declaration, used for enums.
public sealed class TsTypeAlias : ITsType
- Inheritance
-
objectTsTypeAlias
- Implements
Remarks
Enums are emitted as literal unions rather than as a TypeScript enum, because a string enum
refuses assignment of a bare string literal - which is exactly what JSON.parse() produces. Unions are
also fully erased at runtime, so consumers of a DTO need no import for them.
Constructors
TsTypeAlias(TsIdentifier, string)
A TypeScript type alias declaration, used for enums.
public TsTypeAlias(TsIdentifier identifier, string definition)
Parameters
identifierTsIdentifierThe name of the alias and the module it is declared in.
definitionstringThe type expression the alias stands for, e.g.
"a" | "b".
Remarks
Enums are emitted as literal unions rather than as a TypeScript enum, because a string enum
refuses assignment of a bare string literal - which is exactly what JSON.parse() produces. Unions are
also fully erased at runtime, so consumers of a DTO need no import for them.
Properties
Definition
The type expression the alias stands for.
public string Definition { get; }
Property Value
Deprecated
Marks the type as deprecated.
public bool Deprecated { get; set; }
Property Value
Identifier
The name of the type and the module it is declared in.
public TsIdentifier Identifier { get; }
Property Value
Summary
A description of the type for a JSDoc comment.
public string? Summary { get; set; }
Property Value
Methods
GetImports()
Returns all imports needed by the declaration of the type.
public IEnumerable<TsImport> GetImports()
Returns
Write(TsWriter)
Writes the declaration of the type.
public void Write(TsWriter writer)
Parameters
writerTsWriter