Skip to content
On this page

Scale JS / @scale-codec/enum

Module: @scale-codec/enum

Tagged union in TypeScript.

Table of contents

Interfaces

Type Aliases

Functions

Type Aliases

EnumOf

Ƭ EnumOf<V>: V extends Variant<infer E, any, any> ? E : never

Type parameters

NameType
Vextends VariantAny

Defined in

packages/enum/src/lib.ts:25


EnumRecord

Ƭ EnumRecord: Record<string, [] | [any]>

Defined in

packages/enum/src/lib.ts:9


Enumerate

Ƭ Enumerate<E>: { [Tag in keyof E]: E[Tag] extends infer Content extends [] | [any] ? Variant<E, Tag & string, Content> : never }[keyof E]

Type parameters

NameType
Eextends EnumRecord

Defined in

packages/enum/src/lib.ts:21


RustOption

Ƭ RustOption<T>: Enumerate<{ None: [] ; Some: [T] }>

Rust's Option<T> analog

Example

ts
const maybeString: RustOption<string> = variant('None')

Type parameters

Name
T

Defined in

packages/enum/src/lib.ts:83


RustResult

Ƭ RustResult<Ok, Err>: Enumerate<{ Err: [Err] ; Ok: [Ok] }>

Rust's Result<Ok, Err> analog

Example

ts
const file: RustResult<string, Error> = variant('Ok', 'file contents')

Type parameters

Name
Ok
Err

Defined in

packages/enum/src/lib.ts:94


VariantAny

Ƭ VariantAny: Variant<any, any, any>

Defined in

packages/enum/src/lib.ts:19


VariantToFactoryArgs

Ƭ VariantToFactoryArgs<V>: V extends Variant<any, infer Tag, infer Content> ? Content extends [infer C] ? [tag: Tag, content: C] : [tag: Tag] : never

Type parameters

NameType
Vextends VariantAny

Defined in

packages/enum/src/lib.ts:32

Functions

variant

variant<V>(...args): V

Type parameters

NameType
Vextends Variant<any, any, any, V>

Parameters

NameType
...argsVariantToFactoryArgs<V>

Returns

V

Defined in

packages/enum/src/lib.ts:28

variant<E>(...args): Enumerate<E>

Type parameters

NameType
Eextends EnumRecord

Parameters

NameType
...argsVariantToFactoryArgs<Enumerate<E>>

Returns

Enumerate<E>

Defined in

packages/enum/src/lib.ts:29