Inline definition of Record<> to uncollapse Value<T>
This commit is contained in:
parent
481f866ada
commit
1268c4f9bd
|
@ -15,9 +15,29 @@ export * from './dictionary';
|
|||
|
||||
export type DefaultPointer = object;
|
||||
|
||||
export type Value<T extends object = DefaultPointer> = Atom | Compound<T> | T | Annotated<T>;
|
||||
export type Atom = boolean | SingleFloat | DoubleFloat | number | string | Bytes | symbol;
|
||||
export type Compound<T extends object = DefaultPointer> = Record<any, any, T> | Array<Value<T>> | Set<T> | Dictionary<Value<T>, T>;
|
||||
export type Value<T extends object = DefaultPointer> =
|
||||
| Atom
|
||||
| Compound<T>
|
||||
| T
|
||||
| Annotated<T>;
|
||||
export type Atom =
|
||||
| boolean
|
||||
| SingleFloat
|
||||
| DoubleFloat
|
||||
| number
|
||||
| string
|
||||
| Bytes
|
||||
| symbol;
|
||||
export type Compound<T extends object = DefaultPointer> =
|
||||
| (Array<Value<T>> | [Value<T>]) & { label: Value<T> }
|
||||
// ^ expanded from definition of Record<> in record.ts,
|
||||
// because if we use Record<Value<T>, Tuple<Value<T>>, T>,
|
||||
// TypeScript currently complains about circular use of Value<T>,
|
||||
// and if we use Record<any, any, T>, it accepts it but collapses
|
||||
// Value<T> to any.
|
||||
| Array<Value<T>>
|
||||
| Set<T>
|
||||
| Dictionary<Value<T>, T>;
|
||||
|
||||
export function fromJS<T extends object = DefaultPointer>(x: any): Value<T> {
|
||||
switch (typeof x) {
|
||||
|
|
Loading…
Reference in New Issue