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
Name | Type |
---|---|
V | extends VariantAny |
Defined in
EnumRecord
Ƭ EnumRecord: Record
<string
, [] | [any
]>
Defined in
Enumerate
Ƭ Enumerate<E
>: { [Tag in keyof E]: E[Tag] extends infer Content extends [] | [any] ? Variant<E, Tag & string, Content> : never }[keyof E
]
Type parameters
Name | Type |
---|---|
E | extends EnumRecord |
Defined in
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
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
VariantAny
Ƭ VariantAny: Variant
<any
, any
, any
>
Defined in
VariantToFactoryArgs
Ƭ VariantToFactoryArgs<V
>: V
extends Variant
<any
, infer Tag, infer Content> ? Content
extends [infer C] ? [tag: Tag, content: C] : [tag: Tag] : never
Type parameters
Name | Type |
---|---|
V | extends VariantAny |
Defined in
Functions
variant
▸ variant<V
>(...args
): V
Type parameters
Name | Type |
---|---|
V | extends Variant <any , any , any , V > |
Parameters
Name | Type |
---|---|
...args | VariantToFactoryArgs <V > |
Returns
V
Defined in
▸ variant<E
>(...args
): Enumerate
<E
>
Type parameters
Name | Type |
---|---|
E | extends EnumRecord |
Parameters
Name | Type |
---|---|
...args | VariantToFactoryArgs <Enumerate <E >> |
Returns
Enumerate
<E
>