I have no idea why you want to write [...T]
, if it is equivalent to T
.
So if you replace [...T]
with T
, it will work.
See:
interface A {
a: string;
}
interface B {
b: string;
}
type AorB = A | B;
function isA(arg: AorB): arg is A {
return 'a' in arg;
}
function haveSameValue<T extends any[]>(objects: T, keys: (keyof T[number])[]): boolean {
return objects
.slice(1)
.every((obj) => keys.every((key) => obj[key] === objects[0][key]));
}
function foo<T extends AorB[]>(args: T) {
if (args.every(isA)) {
if (haveSameValue(args, ['b'])) {
}
}
}
Technically, the two are not completely the same, but does it matter in this case?