diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 320f4e9f4ddc1..8f38f16c049e4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1077,7 +1077,7 @@ namespace ts { * Returns the first element of an array if non-empty, `undefined` otherwise. */ export function firstOrUndefined(array: ReadonlyArray): T | undefined { - return elementAt(array, 0); + return array.length === 0 ? undefined : array[0]; } export function first(array: ReadonlyArray): T { @@ -1089,7 +1089,7 @@ namespace ts { * Returns the last element of an array if non-empty, `undefined` otherwise. */ export function lastOrUndefined(array: ReadonlyArray): T | undefined { - return elementAt(array, -1); + return array.length === 0 ? undefined : array[array.length - 1]; } export function last(array: ReadonlyArray): T {