You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come up with this idea during investigating #216. Currently, accessing inner runtypes of complex ones such as Record, Tuple, etc. in a generic way requires you to write cumbersome code like following:
This should be possible because JS and TS maintain interoperability between objects and arrays, i.e. arrays can be treated as objects with keys being string of decimal numbers.
If implemented properly, this should also work with Union and Intersect, because TS already does some equivalent stuff for static typing, for example:
typeU={foo: true}|{foo: false};letu!: U;u.foo;// inferred as `boolean`typeI={foo: boolean}&{foo: boolean;bar: string};leti!: I;i.foo;// inferred as `boolean`i.bar;// inferred as `string`
So you should be able to do that on runtypes:
constU=Union(Record({foo: Literal(true)}),Record({foo: Literal(false)}));u.properties.foo;// should be `Union(Literal(true), Literal(false))` or just `Boolean`constI=Intersect(Record({foo: Boolean}),Record({foo: Boolean,bar: String}));i.properties.foo;// should be `Intersect(Boolean, Boolean)` or just `Boolean`i.properties.bar;// should be `String`
The text was updated successfully, but these errors were encountered:
I'm now working on a large refactoring (#339 and the like) of the entire codebase as it's been so hard to maintain due to indirect/tortuous logic rendered by historical reasons. After I've completed it, I'll take this on.
I've come up with this idea during investigating #216. Currently, accessing inner runtypes of complex ones such as
Record
,Tuple
, etc. in a generic way requires you to write cumbersome code like following:But I want to write just this instead:
This should be possible because JS and TS maintain interoperability between objects and arrays, i.e. arrays can be treated as objects with keys being
string
of decimal numbers.If implemented properly, this should also work with
Union
andIntersect
, because TS already does some equivalent stuff for static typing, for example:So you should be able to do that on runtypes:
The text was updated successfully, but these errors were encountered: