Reputation: 1208
I want something like this:
function test(a: something, b: something) { ... }
test([1,2], [3,4]) // This is ok
test([1,2], [3,4,5]) // This is not ok. Arguments have different length. Should throw error
test([1,2,3,4,5], [6,7,8,9,10]) // This is ok too, the length itself doesn't matter, only equality
Is it possible somehow in TypeScript? I would like to change the something
type to implement this, not during runtime.
Upvotes: 0
Views: 66
Reputation: 25800
Do this:
T extends unknown[] | [unknown]
b
: T & { length: T['length'] }
declare function test<T extends unknown[] | [unknown]>(a: T, b: T & { length: T['length'] }): void;
Upvotes: 2