Table of Contents

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
object
TsTypeAlias
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

identifier TsIdentifier

The name of the alias and the module it is declared in.

definition string

The 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

string

Deprecated

Marks the type as deprecated.

public bool Deprecated { get; set; }

Property Value

bool

Identifier

The name of the type and the module it is declared in.

public TsIdentifier Identifier { get; }

Property Value

TsIdentifier

Summary

A description of the type for a JSDoc comment.

public string? Summary { get; set; }

Property Value

string

Methods

GetImports()

Returns all imports needed by the declaration of the type.

public IEnumerable<TsImport> GetImports()

Returns

IEnumerable<TsImport>

Write(TsWriter)

Writes the declaration of the type.

public void Write(TsWriter writer)

Parameters

writer TsWriter