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
Hm, maybe it's not such a good idea? You can't use array.length checks to guard against empty arrays, and sparse arrays add a lot of edge cases: microsoft/TypeScript#38000 (SO thread)
functionprintFirstElement<TupleextendsNonEmptyTuple>(tuple: Tuple){console.log(tuple[0]);}printFirstElement(['a','b','c']);//=> 'a'printFirstElement([]);//=> error TS2345: Argument of type '[]' is not assignable to parameter of type 'NonEmptyTuple'.declareconstarr: string[];if(arr.length>0){printFirstElement(arr);//=> error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'NonEmptyTuple'.}
Similar to #659,
NonEmptyTuple
is a convenient type to expose:type-fest/source/internal.d.ts
Lines 90 to 93 in f63c343
We could augment it to accept a generic type argument:
Upvote & Fund
The text was updated successfully, but these errors were encountered: