13 lines
586 B
TypeScript
13 lines
586 B
TypeScript
|
// @lib: es2015
|
||
|
|
||
|
// test fix for #18112, type guard predicates should narrow returned element
|
||
|
function isNumber(x: any): x is number {
|
||
|
return typeof x === "number";
|
||
|
}
|
||
|
|
||
|
const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true];
|
||
|
const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber);
|
||
|
|
||
|
const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray<string | number | boolean>;
|
||
|
const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber);
|