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'm not sure what this projects stance is on type helpers, but the output for strict unions is pretty verbose.
I am working on a project where we create interfaces very similar to the ones used by this project for strict unions. Our approach uses a type helper to create much smaller output for complex unions.
I'm not sure if this would be a good idea to adopt here, but thought I would share it in case you think it's useful:
typeMyUnion=UnionObject<{foo: number;bar: string;}>;typeMyUnionWithType=UnionObjectWithType<{foo: number;bar: string;}>;constx: MyUnion={bar: '1232',};consty: MyUnion={foo: 1232,bar: undefined,};constz: MyUnionWithType={__type: 'foo',foo: 1232,bar: undefined,};/*Type '{ foo: number; bar: string; }' is not assignable to type '(Pick<{ foo: number; bar: string; }, "foo"> & { bar?: undefined; }) | (Pick<{ foo: number; bar: string; }, "bar"> & { foo?: undefined; })'. Type '{ foo: number; bar: string; }' is not assignable to type 'Pick<{ foo: number; bar: string; }, "bar"> & { foo?: undefined; }'. Type '{ foo: number; bar: string; }' is not assignable to type '{ foo?: undefined; }'. Types of property 'foo' are incompatible. Type 'number' is not assignable to type 'undefined'.ts(2322)*/consterror: MyUnion={foo: 1232,bar: 'asd',};
The text was updated successfully, but these errors were encountered:
I'm not sure what this projects stance is on type helpers, but the output for strict unions is pretty verbose.
I am working on a project where we create interfaces very similar to the ones used by this project for strict unions. Our approach uses a type helper to create much smaller output for complex unions.
I'm not sure if this would be a good idea to adopt here, but thought I would share it in case you think it's useful:
We use the following type helpers:
which could be used like:
The text was updated successfully, but these errors were encountered: