mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
Remove unnecessary *OrUndefined calls (#18889)
* Remove unnecessary *OrUndefined calls * Add 'first'
This commit is contained in:
@@ -866,6 +866,11 @@ namespace ts {
|
||||
return elementAt(array, 0);
|
||||
}
|
||||
|
||||
export function first<T>(array: ReadonlyArray<T>): T {
|
||||
Debug.assert(array.length !== 0);
|
||||
return array[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element of an array if non-empty, `undefined` otherwise.
|
||||
*/
|
||||
@@ -873,6 +878,11 @@ namespace ts {
|
||||
return elementAt(array, -1);
|
||||
}
|
||||
|
||||
export function last<T>(array: ReadonlyArray<T>): T {
|
||||
Debug.assert(array.length !== 0);
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the only element of an array if it contains only one element, `undefined` otherwise.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user