External module "types/literal"
Variables
Const LiteralType
Literal
Type: LiteralTypeConstructor = class<TT, K extends Type<any> = Type<any>> implements IoType<TT> {readonly name: Name = name;readonly type!: K;readonly value!: TT;private _options: Lazy<LiteralTypeOptions<TT, K>>;constructor(options: Lazy<LiteralTypeOptions<TT, K>>) {this._options = options;if (typeof options !== "function") {this._applyOptions();} else {lazyProperties(this, this._applyOptions, ["type", "value"]);}}read<R>(reader: Reader<R>, raw: R): TT {if (this.type.read === undefined) {throw new Incident("NotReadable", {type: this});}return reader.trustInput ? this.clone(this.value) : this.type.read(reader, raw);}write<W>(writer: Writer<W>, value: TT): W {if (this.type.write === undefined) {throw new Incident("NotWritable", {type: this});}return this.type.write(writer, value);}testError(val: TT): Error | undefined {const error: Error | undefined = testError(this.type, val);if (error !== undefined) {return error;}if (!this.type.equals(val, this.value)) {return Incident("InvalidLiteral", "Invalid literal value");}return undefined;}test(value: TT): boolean {return this.type.test(value) && this.type.equals(value, this.value);}equals(val1: TT, val2: TT): boolean {return this.type.equals(val1, val2);}clone(val: TT): TT {return this.type.clone(val);}diff(_oldVal: TT, _newVal: TT): undefined {return;}patch(oldVal: TT, _diff: undefined): TT {return this.type.clone(oldVal);}reverseDiff(_diff: Diff | undefined): undefined {return;}squash(_diff1: undefined, _diff2: undefined): undefined {return;}private _applyOptions(): void {if (this._options === undefined) {throw createLazyOptionsError(this);}const options: LiteralTypeOptions<TT, K> = typeof this._options === "function"? this._options(): this._options;const type: K = options.type;const value: TT = options.value;Object.assign(this, {type, value});}}
Legend
Module
Object literal
Variable
Function
Function with type parameter
Index signature
Type alias
Type alias with type parameter
Enumeration
Enumeration member
Property
Method
Interface
Interface with type parameter
Constructor
Property
Method
Index signature
Class
Class with type parameter
Constructor
Property
Method
Accessor
Index signature
Inherited constructor
Inherited property
Inherited method
Inherited accessor
Protected property
Protected method
Protected accessor
Private property
Private method
Private accessor
Static property
Static method
You may need to explicitly write the type or inference won't pick it. For example, in the case of enum values, inference will pick the type of the enum instead of the specific property you pass.
https://github.com/Microsoft/TypeScript/issues/10195