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
functionrequiresOneItem<T>(array: [T, ...T[]]){}functionisFoo<T>(item: T){returntrue}constarray=[1,2]if(array.some(isFoo)){requiresOneItem(array)// Argument of type 'number[]' is not assignable to parameter of type '[number, ...number[]]'.}interfaceArray<T>{// Uncomment to test:// some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): this is [T, ...T[]];}
Documentation Link
N.A. Calling .some() on an array can only ever return true if the array is not empty.
The text was updated successfully, but these errors were encountered:
Type guards must always return true if the object matches the specified type.
functionrequiresOneItem<T>(array: [T, ...T[]]){}functionisEven(item: number){returnitem%2==0;}constarray: [number, ...number[]]=[1,2]if(array.some(isEven)){requiresOneItem(array)}else{constn=array;// n: never, which is wrong}interfaceArray<T>{// Uncomment to test:some(predicate: (value: T,index: number,array: T[])=>unknown,thisArg?: any): this is [T, ...T[]];}
⚙ Compilation target
es5
⚙ Library
es5
Missing / Incorrect Definition
some
inlib.es5.d.ts
could be defined as follows (return type fromboolean
tothis is [T, ...T[]]
):Sample Code
playground
Documentation Link
N.A. Calling
.some()
on an array can only ever return true if the array is not empty.The text was updated successfully, but these errors were encountered: