-
Notifications
You must be signed in to change notification settings - Fork 329
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
Question: How to make a tuple with more than 5 types? #431
Comments
I've submitted a PR that resolves this, but only for TypeScript 3.8+. If you're using TypeScript 3.8, you can workaround this for now via: type TupleFn = <TCodecs extends readonly t.Mixed[]>(
codecs: TCodecs,
name?: string,
) => t.TupleType<
{
-readonly [K in keyof TCodecs]: TCodecs[K];
},
{
[K in keyof TCodecs]: TCodecs[K] extends t.Mixed
? t.TypeOf<TCodecs[K]>
: unknown;
},
{
[K in keyof TCodecs]: TCodecs[K] extends t.Mixed
? t.OutputOf<TCodecs[K]>
: unknown;
}
>;
const tuple: TupleFn = t.tuple as any; and then use |
Forgot to mention, you will also need to mark the input t.tuple([
t.number, t.number, t.number, t.number, t.number, t.number, t.any, t.number,
] as const) |
You can actually make it work without the type TupleFn = <TCodecs extends readonly [t.Mixed, ...t.Mixed[]]>(
codecs: TCodecs,
name?: string,
) => t.TupleType<
{
-readonly [K in keyof TCodecs]: TCodecs[K];
},
{
[K in keyof TCodecs]: TCodecs[K] extends t.Mixed
? t.TypeOf<TCodecs[K]>
: unknown;
},
{
[K in keyof TCodecs]: TCodecs[K] extends t.Mixed
? t.OutputOf<TCodecs[K]>
: unknown;
}
>;
const tuple: TupleFn = t.tuple as any; This forces TypeScript to infer TCodecs as a tuple, rather than an array. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I use
t.tuple
, it starts to error once I put 6 types. This is my code:t.tuple([t.number, t.number, t.number, t.number, t.number, t.number, t.any, t.number])
The text was updated successfully, but these errors were encountered: