-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support for readonly and generic arrays in the
LastArrayElement
…
… type (#266)
- Loading branch information
Showing
2 changed files
with
10 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import {expectType} from 'tsd'; | ||
import {LastArrayElement} from '../index'; | ||
|
||
declare function lastOf<V extends [any, ...any]>(array: V): LastArrayElement<V>; | ||
declare function lastOf<V extends readonly unknown[]>(array: V): LastArrayElement<V>; | ||
const array: ['foo', 2, 'bar'] = ['foo', 2, 'bar']; | ||
const mixedArray: ['bar', 'foo', 2] = ['bar', 'foo', 2]; | ||
|
||
expectType<'bar'>(lastOf(array)); | ||
expectType<2>(lastOf(mixedArray)); | ||
expectType<string>(lastOf(['a', 'b', 'c'])); | ||
expectType<string | number>(lastOf(['a', 'b', 1])); | ||
expectType<1>(lastOf(['a', 'b', 1] as const)); |