Variant<U>:{ [Key in keyof U]: { [K in Exclude<keyof U, Key>]?: never } & { [K in Key]: U[Key] } }[keyof U]
Utility type for defining a keyed union type as in IPLD Schema. In practice
this just works around typescript limitation that requires discriminant field
on all variants.
typeResult<T, X> = | { ok:T } | { error:X }
constdemo= (result:Result<string, Error>) => { if (result.ok) { // ^^^^^^^^^ Property 'ok' does not exist on type '{ error: Error; }` } }
Using Variant type we can define same union type that works as expected:
Utility type for defining a keyed union type as in IPLD Schema. In practice this just works around typescript limitation that requires discriminant field on all variants.
Using
Variant
type we can define same union type that works as expected: