-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
t.taggedUnion doesn't accept array from 1.5.3 (tuple only) #261
Comments
@kunnix |
@gcanti Which would be great if TypeScript had a nice way to hint for tuple types, but it's not the case yet and for now they're typed as variable-lengths arrays when stored in a variable or passed to I understand this is an elegant way to deal with typing, but it currently prevents storing a list of types in a variable, or to automatically enclose a list of types inside a |
Maybe a couple of helpers can help const tuple = <T extends Array<unknown>>(...t: T): T => {
return t
}
type MakeExact<T extends Array<t.HasProps>> = { [K in keyof T]: T[K] extends t.HasProps ? t.ExactC<T[K]> : never }
const makeExact = <T extends Array<t.HasProps>>(...elements: T): MakeExact<T> => {
return elements.map(e => t.exact(e)) as any
}
// ok
const TU1 = t.taggedUnion('version', [test1, test2])
const allTests = tuple(test1, test2)
// ok
const TU2 = t.taggedUnion('version', allTests)
// ok
const TU3 = t.taggedUnion('version', makeExact(...allTests))
// ok
const TU4 = t.taggedUnion('version', makeExact(test1, test2)) |
Looks like a great workaround! |
@gcanti You probably saw that already, but it might help: microsoft/TypeScript#29510 |
Since the 1.5.3 update,
t.taggedUnion()
doesn't accept arrays anymore, only tuples.Example:
Error:
The text was updated successfully, but these errors were encountered: