Remove unnecessary *OrUndefined calls (#18889)

* Remove unnecessary *OrUndefined calls

* Add 'first'
This commit is contained in:
Andy
2017-10-03 10:24:39 -07:00
committed by GitHub
parent b21d8a4742
commit b111493276
2 changed files with 16 additions and 6 deletions

View File

@@ -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.
*/