diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index cfb300c784d74..48ae8bb2fa2b4 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -9,7 +9,7 @@ interface Array { * predicate. If it is not provided, undefined is used instead. */ find(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined; - find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefined; + find(predicate: (value: T, index: number, obj: T[]) => {} | null | undefined, thisArg?: any): T | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -20,7 +20,7 @@ interface Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): number; + findIndex(predicate: (value: T, index: number, obj: T[]) => {} | null | undefined, thisArg?: any): number; /** * Returns the this object after filling the section identified by start and end with value @@ -324,7 +324,7 @@ interface ReadonlyArray { * predicate. If it is not provided, undefined is used instead. */ find(predicate: (this: void, value: T, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S | undefined; - find(predicate: (value: T, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): T | undefined; + find(predicate: (value: T, index: number, obj: ReadonlyArray) => {} | null | undefined, thisArg?: any): T | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -335,7 +335,7 @@ interface ReadonlyArray { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: T, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): number; + findIndex(predicate: (value: T, index: number, obj: ReadonlyArray) => {} | null | undefined, thisArg?: any): number; } interface RegExp { diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 2917539cfdb6e..da14009a1b4cd 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1104,13 +1104,13 @@ interface ReadonlyArray { * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: T, index: number, array: ReadonlyArray) => {} | null | undefined, thisArg?: any): boolean; /** * Determines whether the specified callback function returns true for any element of an array. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: T, index: number, array: ReadonlyArray) => {} | null | undefined, thisArg?: any): boolean; /** * Performs the specified action for each element in an array. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. @@ -1263,13 +1263,13 @@ interface Array { * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: T, index: number, array: T[]) => {} | null | undefined, thisArg?: any): boolean; /** * Determines whether the specified callback function returns true for any element of an array. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: T, index: number, array: T[]) => {} | null | undefined, thisArg?: any): boolean; /** * Performs the specified action for each element in an array. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. @@ -1690,7 +1690,7 @@ interface Int8Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Int8Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Int8Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -1720,7 +1720,7 @@ interface Int8Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Int8Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Int8Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -1731,7 +1731,7 @@ interface Int8Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Int8Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Int8Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -1857,7 +1857,7 @@ interface Int8Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Int8Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Int8Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -1959,7 +1959,7 @@ interface Uint8Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Uint8Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Uint8Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -1989,7 +1989,7 @@ interface Uint8Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Uint8Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Uint8Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -2000,7 +2000,7 @@ interface Uint8Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Uint8Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Uint8Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -2126,7 +2126,7 @@ interface Uint8Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Uint8Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Uint8Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -2228,7 +2228,7 @@ interface Uint8ClampedArray { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -2258,7 +2258,7 @@ interface Uint8ClampedArray { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Uint8ClampedArray) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Uint8ClampedArray) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -2269,7 +2269,7 @@ interface Uint8ClampedArray { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Uint8ClampedArray) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Uint8ClampedArray) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -2395,7 +2395,7 @@ interface Uint8ClampedArray { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -2496,7 +2496,7 @@ interface Int16Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Int16Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Int16Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -2526,7 +2526,7 @@ interface Int16Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Int16Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Int16Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -2537,7 +2537,7 @@ interface Int16Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Int16Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Int16Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -2662,7 +2662,7 @@ interface Int16Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Int16Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Int16Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -2765,7 +2765,7 @@ interface Uint16Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Uint16Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Uint16Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -2795,7 +2795,7 @@ interface Uint16Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Uint16Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Uint16Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -2806,7 +2806,7 @@ interface Uint16Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Uint16Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Uint16Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -2932,7 +2932,7 @@ interface Uint16Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Uint16Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Uint16Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -3034,7 +3034,7 @@ interface Int32Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Int32Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Int32Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -3064,7 +3064,7 @@ interface Int32Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Int32Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Int32Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -3075,7 +3075,7 @@ interface Int32Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Int32Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Int32Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -3201,7 +3201,7 @@ interface Int32Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Int32Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Int32Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -3303,7 +3303,7 @@ interface Uint32Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Uint32Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Uint32Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -3333,7 +3333,7 @@ interface Uint32Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Uint32Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Uint32Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -3344,7 +3344,7 @@ interface Uint32Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Uint32Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Uint32Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -3469,7 +3469,7 @@ interface Uint32Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Uint32Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Uint32Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -3571,7 +3571,7 @@ interface Float32Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Float32Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Float32Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -3601,7 +3601,7 @@ interface Float32Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Float32Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Float32Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -3612,7 +3612,7 @@ interface Float32Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Float32Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Float32Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -3738,7 +3738,7 @@ interface Float32Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Float32Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Float32Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. @@ -3841,7 +3841,7 @@ interface Float64Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - every(callbackfn: (value: number, index: number, array: Float64Array) => boolean, thisArg?: any): boolean; + every(callbackfn: (value: number, index: number, array: Float64Array) => {} | null | undefined, thisArg?: any): boolean; /** * Returns the this object after filling the section identified by start and end with value @@ -3871,7 +3871,7 @@ interface Float64Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: number, index: number, obj: Float64Array) => boolean, thisArg?: any): number | undefined; + find(predicate: (value: number, index: number, obj: Float64Array) => {} | null | undefined, thisArg?: any): number | undefined; /** * Returns the index of the first element in the array where predicate is true, and -1 @@ -3882,7 +3882,7 @@ interface Float64Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - findIndex(predicate: (value: number, index: number, obj: Float64Array) => boolean, thisArg?: any): number; + findIndex(predicate: (value: number, index: number, obj: Float64Array) => {} | null | undefined, thisArg?: any): number; /** * Performs the specified action for each element in an array. @@ -4008,7 +4008,7 @@ interface Float64Array { * @param thisArg An object to which the this keyword can refer in the callbackfn function. * If thisArg is omitted, undefined is used as the this value. */ - some(callbackfn: (value: number, index: number, array: Float64Array) => boolean, thisArg?: any): boolean; + some(callbackfn: (value: number, index: number, array: Float64Array) => {} | null | undefined, thisArg?: any): boolean; /** * Sorts an array. diff --git a/tests/baselines/reference/2dArrays.types b/tests/baselines/reference/2dArrays.types index f9f0e726dde3f..f44236dfbf76c 100644 --- a/tests/baselines/reference/2dArrays.types +++ b/tests/baselines/reference/2dArrays.types @@ -24,11 +24,11 @@ class Board { return this.ships.every(function (val) { return val.isSunk; }); >this.ships.every(function (val) { return val.isSunk; }) : boolean ->this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean +>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => {}, thisArg?: any) => boolean >this.ships : Ship[] >this : this >ships : Ship[] ->every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean +>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => {}, thisArg?: any) => boolean >function (val) { return val.isSunk; } : (val: Ship) => boolean >val : Ship >val.isSunk : boolean diff --git a/tests/baselines/reference/arrayEvery.errors.txt b/tests/baselines/reference/arrayEvery.errors.txt new file mode 100644 index 0000000000000..8acdadb6afafa --- /dev/null +++ b/tests/baselines/reference/arrayEvery.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/arrayEvery.ts(12,11): error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. +tests/cases/compiler/arrayEvery.ts(14,11): error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. + + +==== tests/cases/compiler/arrayEvery.ts (2 errors) ==== + // Tests fix for #27496, predicates should not have to return booleans + const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } + ]; + const fizz = [ + { name: 'buzz' }, + { name: 'fizzbuzz' } + ]; + + foo.every(x => {}); + ~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.every(x => ""); + foo.every(x => { return; }); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.every(x => { return null; }); + foo.every(x => { return undefined; }); + foo.every(x => x.name); + fizz.every(x => x.name); \ No newline at end of file diff --git a/tests/baselines/reference/arrayEvery.js b/tests/baselines/reference/arrayEvery.js new file mode 100644 index 0000000000000..22e77daedf51c --- /dev/null +++ b/tests/baselines/reference/arrayEvery.js @@ -0,0 +1,38 @@ +//// [arrayEvery.ts] +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +const fizz = [ + { name: 'buzz' }, + { name: 'fizzbuzz' } +]; + +foo.every(x => {}); +foo.every(x => ""); +foo.every(x => { return; }); +foo.every(x => { return null; }); +foo.every(x => { return undefined; }); +foo.every(x => x.name); +fizz.every(x => x.name); + +//// [arrayEvery.js] +// Tests fix for #27496, predicates should not have to return booleans +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +var fizz = [ + { name: 'buzz' }, + { name: 'fizzbuzz' } +]; +foo.every(function (x) { }); +foo.every(function (x) { return ""; }); +foo.every(function (x) { return; }); +foo.every(function (x) { return null; }); +foo.every(function (x) { return undefined; }); +foo.every(function (x) { return x.name; }); +fizz.every(function (x) { return x.name; }); diff --git a/tests/baselines/reference/arrayEvery.symbols b/tests/baselines/reference/arrayEvery.symbols new file mode 100644 index 0000000000000..c484f8cd7d9a4 --- /dev/null +++ b/tests/baselines/reference/arrayEvery.symbols @@ -0,0 +1,75 @@ +=== tests/cases/compiler/arrayEvery.ts === +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) + + { name: 'bar' }, +>name : Symbol(name, Decl(arrayEvery.ts, 2, 5)) + + { name: null }, +>name : Symbol(name, Decl(arrayEvery.ts, 3, 5)) + + { name: 'baz' } +>name : Symbol(name, Decl(arrayEvery.ts, 4, 5)) + +]; +const fizz = [ +>fizz : Symbol(fizz, Decl(arrayEvery.ts, 6, 5)) + + { name: 'buzz' }, +>name : Symbol(name, Decl(arrayEvery.ts, 7, 5)) + + { name: 'fizzbuzz' } +>name : Symbol(name, Decl(arrayEvery.ts, 8, 5)) + +]; + +foo.every(x => {}); +>foo.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 11, 10)) + +foo.every(x => ""); +>foo.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 12, 10)) + +foo.every(x => { return; }); +>foo.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 13, 10)) + +foo.every(x => { return null; }); +>foo.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 14, 10)) + +foo.every(x => { return undefined; }); +>foo.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 15, 10)) +>undefined : Symbol(undefined) + +foo.every(x => x.name); +>foo.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayEvery.ts, 1, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 16, 10)) +>x.name : Symbol(name, Decl(arrayEvery.ts, 2, 5)) +>x : Symbol(x, Decl(arrayEvery.ts, 16, 10)) +>name : Symbol(name, Decl(arrayEvery.ts, 2, 5)) + +fizz.every(x => x.name); +>fizz.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>fizz : Symbol(fizz, Decl(arrayEvery.ts, 6, 5)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arrayEvery.ts, 17, 11)) +>x.name : Symbol(name, Decl(arrayEvery.ts, 7, 5)) +>x : Symbol(x, Decl(arrayEvery.ts, 17, 11)) +>name : Symbol(name, Decl(arrayEvery.ts, 7, 5)) + diff --git a/tests/baselines/reference/arrayEvery.types b/tests/baselines/reference/arrayEvery.types new file mode 100644 index 0000000000000..a935692b4bc7c --- /dev/null +++ b/tests/baselines/reference/arrayEvery.types @@ -0,0 +1,103 @@ +=== tests/cases/compiler/arrayEvery.ts === +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : { name: string; }[] +>[ { name: 'bar' }, { name: null }, { name: 'baz' }] : { name: string; }[] + + { name: 'bar' }, +>{ name: 'bar' } : { name: string; } +>name : string +>'bar' : "bar" + + { name: null }, +>{ name: null } : { name: null; } +>name : null +>null : null + + { name: 'baz' } +>{ name: 'baz' } : { name: string; } +>name : string +>'baz' : "baz" + +]; +const fizz = [ +>fizz : { name: string; }[] +>[ { name: 'buzz' }, { name: 'fizzbuzz' }] : { name: string; }[] + + { name: 'buzz' }, +>{ name: 'buzz' } : { name: string; } +>name : string +>'buzz' : "buzz" + + { name: 'fizzbuzz' } +>{ name: 'fizzbuzz' } : { name: string; } +>name : string +>'fizzbuzz' : "fizzbuzz" + +]; + +foo.every(x => {}); +>foo.every(x => {}) : boolean +>foo.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => {} : (x: { name: string; }) => void +>x : { name: string; } + +foo.every(x => ""); +>foo.every(x => "") : boolean +>foo.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => "" : (x: { name: string; }) => string +>x : { name: string; } +>"" : "" + +foo.every(x => { return; }); +>foo.every(x => { return; }) : boolean +>foo.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => { return; } : (x: { name: string; }) => void +>x : { name: string; } + +foo.every(x => { return null; }); +>foo.every(x => { return null; }) : boolean +>foo.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => { return null; } : (x: { name: string; }) => any +>x : { name: string; } +>null : null + +foo.every(x => { return undefined; }); +>foo.every(x => { return undefined; }) : boolean +>foo.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => { return undefined; } : (x: { name: string; }) => any +>x : { name: string; } +>undefined : undefined + +foo.every(x => x.name); +>foo.every(x => x.name) : boolean +>foo.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + +fizz.every(x => x.name); +>fizz.every(x => x.name) : boolean +>fizz.every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>fizz : { name: string; }[] +>every : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + diff --git a/tests/baselines/reference/arrayFind.errors.txt b/tests/baselines/reference/arrayFind.errors.txt new file mode 100644 index 0000000000000..14549b6e84222 --- /dev/null +++ b/tests/baselines/reference/arrayFind.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/arrayFind.ts(21,10): error TS2345: Argument of type '(this: void, x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. +tests/cases/compiler/arrayFind.ts(23,10): error TS2345: Argument of type '(this: void, x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. + + +==== tests/cases/compiler/arrayFind.ts (2 errors) ==== + // 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; + const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); + + + + // Tests fix for #27496, predicates should not have to return booleans + const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } + ]; + + foo.find(x => {}); + ~~~~~~~ +!!! error TS2345: Argument of type '(this: void, x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.find(x => ""); + foo.find(x => { return; }); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(this: void, x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.find(x => { return null; }); + foo.find(x => { return undefined; }); + foo.find(x => x.name); \ No newline at end of file diff --git a/tests/baselines/reference/arrayFind.js b/tests/baselines/reference/arrayFind.js index 1926c3a8dcc15..4f8f1c5fc723c 100644 --- a/tests/baselines/reference/arrayFind.js +++ b/tests/baselines/reference/arrayFind.js @@ -9,7 +9,22 @@ const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(is const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); - + + + +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; + +foo.find(x => {}); +foo.find(x => ""); +foo.find(x => { return; }); +foo.find(x => { return null; }); +foo.find(x => { return undefined; }); +foo.find(x => x.name); //// [arrayFind.js] // test fix for #18112, type guard predicates should narrow returned element @@ -20,3 +35,15 @@ var arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true]; var foundNumber = arrayOfStringsNumbersAndBooleans.find(isNumber); var readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans; var readonlyFoundNumber = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); +// Tests fix for #27496, predicates should not have to return booleans +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +foo.find(function (x) { }); +foo.find(function (x) { return ""; }); +foo.find(function (x) { return; }); +foo.find(function (x) { return null; }); +foo.find(function (x) { return undefined; }); +foo.find(function (x) { return x.name; }); diff --git a/tests/baselines/reference/arrayFind.symbols b/tests/baselines/reference/arrayFind.symbols index 3564f7f3edd04..b891416a09821 100644 --- a/tests/baselines/reference/arrayFind.symbols +++ b/tests/baselines/reference/arrayFind.symbols @@ -31,3 +31,60 @@ const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAnd >find : Symbol(ReadonlyArray.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >isNumber : Symbol(isNumber, Decl(arrayFind.ts, 0, 0)) + + +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) + + { name: 'bar' }, +>name : Symbol(name, Decl(arrayFind.ts, 15, 3)) + + { name: null }, +>name : Symbol(name, Decl(arrayFind.ts, 16, 3)) + + { name: 'baz' } +>name : Symbol(name, Decl(arrayFind.ts, 17, 3)) + +]; + +foo.find(x => {}); +>foo.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFind.ts, 20, 9)) + +foo.find(x => ""); +>foo.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFind.ts, 21, 9)) + +foo.find(x => { return; }); +>foo.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFind.ts, 22, 9)) + +foo.find(x => { return null; }); +>foo.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFind.ts, 23, 9)) + +foo.find(x => { return undefined; }); +>foo.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFind.ts, 24, 9)) +>undefined : Symbol(undefined) + +foo.find(x => x.name); +>foo.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFind.ts, 14, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFind.ts, 25, 9)) +>x.name : Symbol(name, Decl(arrayFind.ts, 15, 3)) +>x : Symbol(x, Decl(arrayFind.ts, 25, 9)) +>name : Symbol(name, Decl(arrayFind.ts, 15, 3)) + diff --git a/tests/baselines/reference/arrayFind.types b/tests/baselines/reference/arrayFind.types index 8bc1b36f7f642..4a9aa2df57b72 100644 --- a/tests/baselines/reference/arrayFind.types +++ b/tests/baselines/reference/arrayFind.types @@ -24,9 +24,9 @@ const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true] const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber); >foundNumber : number >arrayOfStringsNumbersAndBooleans.find(isNumber) : number ->arrayOfStringsNumbersAndBooleans.find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => boolean, thisArg?: any): string | number | boolean; } +>arrayOfStringsNumbersAndBooleans.find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => {}, thisArg?: any): string | number | boolean; } >arrayOfStringsNumbersAndBooleans : (string | number | boolean)[] ->find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => boolean, thisArg?: any): string | number | boolean; } +>find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => {}, thisArg?: any): string | number | boolean; } >isNumber : (x: any) => x is number const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; @@ -37,8 +37,86 @@ const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBoolean const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); >readonlyFoundNumber : number >readonlyArrayOfStringsNumbersAndBooleans.find(isNumber) : number ->readonlyArrayOfStringsNumbersAndBooleans.find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): string | number | boolean; } +>readonlyArrayOfStringsNumbersAndBooleans.find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray) => {}, thisArg?: any): string | number | boolean; } >readonlyArrayOfStringsNumbersAndBooleans : ReadonlyArray ->find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): string | number | boolean; } +>find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray) => {}, thisArg?: any): string | number | boolean; } >isNumber : (x: any) => x is number + + +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : { name: string; }[] +>[ { name: 'bar' }, { name: null }, { name: 'baz' }] : { name: string; }[] + + { name: 'bar' }, +>{ name: 'bar' } : { name: string; } +>name : string +>'bar' : "bar" + + { name: null }, +>{ name: null } : { name: null; } +>name : null +>null : null + + { name: 'baz' } +>{ name: 'baz' } : { name: string; } +>name : string +>'baz' : "baz" + +]; + +foo.find(x => {}); +>foo.find(x => {}) : any +>foo.find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>foo : { name: string; }[] +>find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>x => {} : (this: void, x: { name: string; }) => void +>x : { name: string; } + +foo.find(x => ""); +>foo.find(x => "") : { name: string; } +>foo.find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>foo : { name: string; }[] +>find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>x => "" : (this: void, x: { name: string; }) => string +>x : { name: string; } +>"" : "" + +foo.find(x => { return; }); +>foo.find(x => { return; }) : any +>foo.find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>foo : { name: string; }[] +>find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>x => { return; } : (this: void, x: { name: string; }) => void +>x : { name: string; } + +foo.find(x => { return null; }); +>foo.find(x => { return null; }) : { name: string; } +>foo.find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>foo : { name: string; }[] +>find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>x => { return null; } : (this: void, x: { name: string; }) => any +>x : { name: string; } +>null : null + +foo.find(x => { return undefined; }); +>foo.find(x => { return undefined; }) : { name: string; } +>foo.find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>foo : { name: string; }[] +>find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>x => { return undefined; } : (this: void, x: { name: string; }) => any +>x : { name: string; } +>undefined : undefined + +foo.find(x => x.name); +>foo.find(x => x.name) : { name: string; } +>foo.find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>foo : { name: string; }[] +>find : { (predicate: (this: void, value: { name: string; }, index: number, obj: { name: string; }[]) => value is S, thisArg?: any): S; (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any): { name: string; }; } +>x => x.name : (this: void, x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + diff --git a/tests/baselines/reference/arrayFindIndex.errors.txt b/tests/baselines/reference/arrayFindIndex.errors.txt new file mode 100644 index 0000000000000..33e2aa4c609d4 --- /dev/null +++ b/tests/baselines/reference/arrayFindIndex.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/arrayFindIndex.ts(11,15): error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. +tests/cases/compiler/arrayFindIndex.ts(13,15): error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. + + +==== tests/cases/compiler/arrayFindIndex.ts (2 errors) ==== + // Tests fix for #27496, predicates should not have to return booleans + const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } + ]; + const fizz = [ + { name: null } + ]; + + foo.findIndex(x => {}); + ~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.findIndex(x => ""); + foo.findIndex(x => { return; }); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, obj: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.findIndex(x => { return null; }); + foo.findIndex(x => { return undefined; }); + foo.findIndex(x => x.name); + fizz.findIndex(x => x.name); \ No newline at end of file diff --git a/tests/baselines/reference/arrayFindIndex.js b/tests/baselines/reference/arrayFindIndex.js new file mode 100644 index 0000000000000..eed0555d3ef8b --- /dev/null +++ b/tests/baselines/reference/arrayFindIndex.js @@ -0,0 +1,36 @@ +//// [arrayFindIndex.ts] +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +const fizz = [ + { name: null } +]; + +foo.findIndex(x => {}); +foo.findIndex(x => ""); +foo.findIndex(x => { return; }); +foo.findIndex(x => { return null; }); +foo.findIndex(x => { return undefined; }); +foo.findIndex(x => x.name); +fizz.findIndex(x => x.name); + +//// [arrayFindIndex.js] +// Tests fix for #27496, predicates should not have to return booleans +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +var fizz = [ + { name: null } +]; +foo.findIndex(function (x) { }); +foo.findIndex(function (x) { return ""; }); +foo.findIndex(function (x) { return; }); +foo.findIndex(function (x) { return null; }); +foo.findIndex(function (x) { return undefined; }); +foo.findIndex(function (x) { return x.name; }); +fizz.findIndex(function (x) { return x.name; }); diff --git a/tests/baselines/reference/arrayFindIndex.symbols b/tests/baselines/reference/arrayFindIndex.symbols new file mode 100644 index 0000000000000..43397af46d6b3 --- /dev/null +++ b/tests/baselines/reference/arrayFindIndex.symbols @@ -0,0 +1,72 @@ +=== tests/cases/compiler/arrayFindIndex.ts === +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) + + { name: 'bar' }, +>name : Symbol(name, Decl(arrayFindIndex.ts, 2, 5)) + + { name: null }, +>name : Symbol(name, Decl(arrayFindIndex.ts, 3, 5)) + + { name: 'baz' } +>name : Symbol(name, Decl(arrayFindIndex.ts, 4, 5)) + +]; +const fizz = [ +>fizz : Symbol(fizz, Decl(arrayFindIndex.ts, 6, 5)) + + { name: null } +>name : Symbol(name, Decl(arrayFindIndex.ts, 7, 5)) + +]; + +foo.findIndex(x => {}); +>foo.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 10, 14)) + +foo.findIndex(x => ""); +>foo.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 11, 14)) + +foo.findIndex(x => { return; }); +>foo.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 12, 14)) + +foo.findIndex(x => { return null; }); +>foo.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 13, 14)) + +foo.findIndex(x => { return undefined; }); +>foo.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 14, 14)) +>undefined : Symbol(undefined) + +foo.findIndex(x => x.name); +>foo.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFindIndex.ts, 1, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 15, 14)) +>x.name : Symbol(name, Decl(arrayFindIndex.ts, 2, 5)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 15, 14)) +>name : Symbol(name, Decl(arrayFindIndex.ts, 2, 5)) + +fizz.findIndex(x => x.name); +>fizz.findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>fizz : Symbol(fizz, Decl(arrayFindIndex.ts, 6, 5)) +>findIndex : Symbol(Array.findIndex, Decl(lib.es2015.core.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 16, 15)) +>x.name : Symbol(name, Decl(arrayFindIndex.ts, 7, 5)) +>x : Symbol(x, Decl(arrayFindIndex.ts, 16, 15)) +>name : Symbol(name, Decl(arrayFindIndex.ts, 7, 5)) + diff --git a/tests/baselines/reference/arrayFindIndex.types b/tests/baselines/reference/arrayFindIndex.types new file mode 100644 index 0000000000000..e37b9c50619d1 --- /dev/null +++ b/tests/baselines/reference/arrayFindIndex.types @@ -0,0 +1,98 @@ +=== tests/cases/compiler/arrayFindIndex.ts === +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : { name: string; }[] +>[ { name: 'bar' }, { name: null }, { name: 'baz' }] : { name: string; }[] + + { name: 'bar' }, +>{ name: 'bar' } : { name: string; } +>name : string +>'bar' : "bar" + + { name: null }, +>{ name: null } : { name: null; } +>name : null +>null : null + + { name: 'baz' } +>{ name: 'baz' } : { name: string; } +>name : string +>'baz' : "baz" + +]; +const fizz = [ +>fizz : { name: any; }[] +>[ { name: null }] : { name: null; }[] + + { name: null } +>{ name: null } : { name: null; } +>name : null +>null : null + +]; + +foo.findIndex(x => {}); +>foo.findIndex(x => {}) : number +>foo.findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>foo : { name: string; }[] +>findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>x => {} : (x: { name: string; }) => void +>x : { name: string; } + +foo.findIndex(x => ""); +>foo.findIndex(x => "") : number +>foo.findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>foo : { name: string; }[] +>findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>x => "" : (x: { name: string; }) => string +>x : { name: string; } +>"" : "" + +foo.findIndex(x => { return; }); +>foo.findIndex(x => { return; }) : number +>foo.findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>foo : { name: string; }[] +>findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>x => { return; } : (x: { name: string; }) => void +>x : { name: string; } + +foo.findIndex(x => { return null; }); +>foo.findIndex(x => { return null; }) : number +>foo.findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>foo : { name: string; }[] +>findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>x => { return null; } : (x: { name: string; }) => any +>x : { name: string; } +>null : null + +foo.findIndex(x => { return undefined; }); +>foo.findIndex(x => { return undefined; }) : number +>foo.findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>foo : { name: string; }[] +>findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>x => { return undefined; } : (x: { name: string; }) => any +>x : { name: string; } +>undefined : undefined + +foo.findIndex(x => x.name); +>foo.findIndex(x => x.name) : number +>foo.findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>foo : { name: string; }[] +>findIndex : (predicate: (value: { name: string; }, index: number, obj: { name: string; }[]) => {}, thisArg?: any) => number +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + +fizz.findIndex(x => x.name); +>fizz.findIndex(x => x.name) : number +>fizz.findIndex : (predicate: (value: { name: any; }, index: number, obj: { name: any; }[]) => {}, thisArg?: any) => number +>fizz : { name: any; }[] +>findIndex : (predicate: (value: { name: any; }, index: number, obj: { name: any; }[]) => {}, thisArg?: any) => number +>x => x.name : (x: { name: any; }) => any +>x : { name: any; } +>x.name : any +>x : { name: any; } +>name : any + diff --git a/tests/baselines/reference/arraySome.errors.txt b/tests/baselines/reference/arraySome.errors.txt new file mode 100644 index 0000000000000..1ba019e032947 --- /dev/null +++ b/tests/baselines/reference/arraySome.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/arraySome.ts(12,10): error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. +tests/cases/compiler/arraySome.ts(14,10): error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. + Type 'void' is not assignable to type '{}'. + + +==== tests/cases/compiler/arraySome.ts (2 errors) ==== + // Tests fix for #27496, predicates should not have to return booleans + const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } + ]; + const fizz = [ + { name: null }, + { name: null } + ]; + + foo.some(x => {}); + ~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.some(x => ""); + foo.some(x => { return; }); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => void' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => {}'. +!!! error TS2345: Type 'void' is not assignable to type '{}'. + foo.some(x => { return null; }); + foo.some(x => { return undefined; }); + foo.some(x => x.name); + fizz.some(x => x.name); \ No newline at end of file diff --git a/tests/baselines/reference/arraySome.js b/tests/baselines/reference/arraySome.js new file mode 100644 index 0000000000000..94d121ad8fec7 --- /dev/null +++ b/tests/baselines/reference/arraySome.js @@ -0,0 +1,38 @@ +//// [arraySome.ts] +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +const fizz = [ + { name: null }, + { name: null } +]; + +foo.some(x => {}); +foo.some(x => ""); +foo.some(x => { return; }); +foo.some(x => { return null; }); +foo.some(x => { return undefined; }); +foo.some(x => x.name); +fizz.some(x => x.name); + +//// [arraySome.js] +// Tests fix for #27496, predicates should not have to return booleans +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +var fizz = [ + { name: null }, + { name: null } +]; +foo.some(function (x) { }); +foo.some(function (x) { return ""; }); +foo.some(function (x) { return; }); +foo.some(function (x) { return null; }); +foo.some(function (x) { return undefined; }); +foo.some(function (x) { return x.name; }); +fizz.some(function (x) { return x.name; }); diff --git a/tests/baselines/reference/arraySome.symbols b/tests/baselines/reference/arraySome.symbols new file mode 100644 index 0000000000000..4a5c1fa3fc749 --- /dev/null +++ b/tests/baselines/reference/arraySome.symbols @@ -0,0 +1,75 @@ +=== tests/cases/compiler/arraySome.ts === +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) + + { name: 'bar' }, +>name : Symbol(name, Decl(arraySome.ts, 2, 5)) + + { name: null }, +>name : Symbol(name, Decl(arraySome.ts, 3, 5)) + + { name: 'baz' } +>name : Symbol(name, Decl(arraySome.ts, 4, 5)) + +]; +const fizz = [ +>fizz : Symbol(fizz, Decl(arraySome.ts, 6, 5)) + + { name: null }, +>name : Symbol(name, Decl(arraySome.ts, 7, 5)) + + { name: null } +>name : Symbol(name, Decl(arraySome.ts, 8, 5)) + +]; + +foo.some(x => {}); +>foo.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 11, 9)) + +foo.some(x => ""); +>foo.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 12, 9)) + +foo.some(x => { return; }); +>foo.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 13, 9)) + +foo.some(x => { return null; }); +>foo.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 14, 9)) + +foo.some(x => { return undefined; }); +>foo.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 15, 9)) +>undefined : Symbol(undefined) + +foo.some(x => x.name); +>foo.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(arraySome.ts, 1, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 16, 9)) +>x.name : Symbol(name, Decl(arraySome.ts, 2, 5)) +>x : Symbol(x, Decl(arraySome.ts, 16, 9)) +>name : Symbol(name, Decl(arraySome.ts, 2, 5)) + +fizz.some(x => x.name); +>fizz.some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>fizz : Symbol(fizz, Decl(arraySome.ts, 6, 5)) +>some : Symbol(Array.some, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(arraySome.ts, 17, 10)) +>x.name : Symbol(name, Decl(arraySome.ts, 7, 5)) +>x : Symbol(x, Decl(arraySome.ts, 17, 10)) +>name : Symbol(name, Decl(arraySome.ts, 7, 5)) + diff --git a/tests/baselines/reference/arraySome.types b/tests/baselines/reference/arraySome.types new file mode 100644 index 0000000000000..d70154279d378 --- /dev/null +++ b/tests/baselines/reference/arraySome.types @@ -0,0 +1,103 @@ +=== tests/cases/compiler/arraySome.ts === +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ +>foo : { name: string; }[] +>[ { name: 'bar' }, { name: null }, { name: 'baz' }] : { name: string; }[] + + { name: 'bar' }, +>{ name: 'bar' } : { name: string; } +>name : string +>'bar' : "bar" + + { name: null }, +>{ name: null } : { name: null; } +>name : null +>null : null + + { name: 'baz' } +>{ name: 'baz' } : { name: string; } +>name : string +>'baz' : "baz" + +]; +const fizz = [ +>fizz : { name: any; }[] +>[ { name: null }, { name: null }] : { name: null; }[] + + { name: null }, +>{ name: null } : { name: null; } +>name : null +>null : null + + { name: null } +>{ name: null } : { name: null; } +>name : null +>null : null + +]; + +foo.some(x => {}); +>foo.some(x => {}) : boolean +>foo.some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => {} : (x: { name: string; }) => void +>x : { name: string; } + +foo.some(x => ""); +>foo.some(x => "") : boolean +>foo.some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => "" : (x: { name: string; }) => string +>x : { name: string; } +>"" : "" + +foo.some(x => { return; }); +>foo.some(x => { return; }) : boolean +>foo.some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => { return; } : (x: { name: string; }) => void +>x : { name: string; } + +foo.some(x => { return null; }); +>foo.some(x => { return null; }) : boolean +>foo.some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => { return null; } : (x: { name: string; }) => any +>x : { name: string; } +>null : null + +foo.some(x => { return undefined; }); +>foo.some(x => { return undefined; }) : boolean +>foo.some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => { return undefined; } : (x: { name: string; }) => any +>x : { name: string; } +>undefined : undefined + +foo.some(x => x.name); +>foo.some(x => x.name) : boolean +>foo.some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>foo : { name: string; }[] +>some : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => {}, thisArg?: any) => boolean +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + +fizz.some(x => x.name); +>fizz.some(x => x.name) : boolean +>fizz.some : (callbackfn: (value: { name: any; }, index: number, array: { name: any; }[]) => {}, thisArg?: any) => boolean +>fizz : { name: any; }[] +>some : (callbackfn: (value: { name: any; }, index: number, array: { name: any; }[]) => {}, thisArg?: any) => boolean +>x => x.name : (x: { name: any; }) => any +>x : { name: any; } +>x.name : any +>x : { name: any; } +>name : any + diff --git a/tests/baselines/reference/contextuallyTypedIife.types b/tests/baselines/reference/contextuallyTypedIife.types index df0b788459476..652cfb5227ced 100644 --- a/tests/baselines/reference/contextuallyTypedIife.types +++ b/tests/baselines/reference/contextuallyTypedIife.types @@ -105,9 +105,9 @@ >(...numbers) => numbers.every(n => n > 0) : (numbers_0: number, numbers_1: number, numbers_2: number) => boolean >numbers : [number, number, number] >numbers.every(n => n > 0) : boolean ->numbers.every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean +>numbers.every : (callbackfn: (value: number, index: number, array: number[]) => {}, thisArg?: any) => boolean >numbers : [number, number, number] ->every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean +>every : (callbackfn: (value: number, index: number, array: number[]) => {}, thisArg?: any) => boolean >n => n > 0 : (n: number) => boolean >n : number >n > 0 : boolean @@ -123,9 +123,9 @@ >(...mixed) => mixed.every(n => !!n) : (mixed_0: number, mixed_1: string, mixed_2: string) => boolean >mixed : [number, string, string] >mixed.every(n => !!n) : boolean ->mixed.every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => boolean, thisArg?: any) => boolean +>mixed.every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => {}, thisArg?: any) => boolean >mixed : [number, string, string] ->every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => boolean, thisArg?: any) => boolean +>every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => {}, thisArg?: any) => boolean >n => !!n : (n: string | number) => boolean >n : string | number >!!n : boolean @@ -141,9 +141,9 @@ >(...noNumbers) => noNumbers.some(n => n > 0) : () => boolean >noNumbers : [] >noNumbers.some(n => n > 0) : boolean ->noNumbers.some : (callbackfn: (value: never, index: number, array: never[]) => boolean, thisArg?: any) => boolean +>noNumbers.some : (callbackfn: (value: never, index: number, array: never[]) => {}, thisArg?: any) => boolean >noNumbers : [] ->some : (callbackfn: (value: never, index: number, array: never[]) => boolean, thisArg?: any) => boolean +>some : (callbackfn: (value: never, index: number, array: never[]) => {}, thisArg?: any) => boolean >n => n > 0 : (n: never) => boolean >n : never >n > 0 : boolean diff --git a/tests/baselines/reference/contextuallyTypedIifeStrict.types b/tests/baselines/reference/contextuallyTypedIifeStrict.types index e20c08a20debf..2f49be364e533 100644 --- a/tests/baselines/reference/contextuallyTypedIifeStrict.types +++ b/tests/baselines/reference/contextuallyTypedIifeStrict.types @@ -105,9 +105,9 @@ >(...numbers) => numbers.every(n => n > 0) : (numbers_0: number, numbers_1: number, numbers_2: number) => boolean >numbers : [number, number, number] >numbers.every(n => n > 0) : boolean ->numbers.every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean +>numbers.every : (callbackfn: (value: number, index: number, array: number[]) => {} | null | undefined, thisArg?: any) => boolean >numbers : [number, number, number] ->every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean +>every : (callbackfn: (value: number, index: number, array: number[]) => {} | null | undefined, thisArg?: any) => boolean >n => n > 0 : (n: number) => boolean >n : number >n > 0 : boolean @@ -123,9 +123,9 @@ >(...mixed) => mixed.every(n => !!n) : (mixed_0: number, mixed_1: string, mixed_2: string) => boolean >mixed : [number, string, string] >mixed.every(n => !!n) : boolean ->mixed.every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => boolean, thisArg?: any) => boolean +>mixed.every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => {} | null | undefined, thisArg?: any) => boolean >mixed : [number, string, string] ->every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => boolean, thisArg?: any) => boolean +>every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => {} | null | undefined, thisArg?: any) => boolean >n => !!n : (n: string | number) => boolean >n : string | number >!!n : boolean @@ -141,9 +141,9 @@ >(...noNumbers) => noNumbers.some(n => n > 0) : () => boolean >noNumbers : [] >noNumbers.some(n => n > 0) : boolean ->noNumbers.some : (callbackfn: (value: never, index: number, array: never[]) => boolean, thisArg?: any) => boolean +>noNumbers.some : (callbackfn: (value: never, index: number, array: never[]) => {} | null | undefined, thisArg?: any) => boolean >noNumbers : [] ->some : (callbackfn: (value: never, index: number, array: never[]) => boolean, thisArg?: any) => boolean +>some : (callbackfn: (value: never, index: number, array: never[]) => {} | null | undefined, thisArg?: any) => boolean >n => n > 0 : (n: never) => boolean >n : never >n > 0 : boolean diff --git a/tests/baselines/reference/duplicateLocalVariable1.types b/tests/baselines/reference/duplicateLocalVariable1.types index d19007d90aa31..022092fe41fcc 100644 --- a/tests/baselines/reference/duplicateLocalVariable1.types +++ b/tests/baselines/reference/duplicateLocalVariable1.types @@ -41,9 +41,9 @@ export class TestRunner { return (arg1.every(function (val, index) { return val === arg2[index] })); >(arg1.every(function (val, index) { return val === arg2[index] })) : boolean >arg1.every(function (val, index) { return val === arg2[index] }) : boolean ->arg1.every : (callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any) => boolean +>arg1.every : (callbackfn: (value: any, index: number, array: any[]) => {}, thisArg?: any) => boolean >arg1 : any[] ->every : (callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any) => boolean +>every : (callbackfn: (value: any, index: number, array: any[]) => {}, thisArg?: any) => boolean >function (val, index) { return val === arg2[index] } : (val: any, index: number) => boolean >val : any >index : number diff --git a/tests/baselines/reference/parserharness.types b/tests/baselines/reference/parserharness.types index 222ac9ab94559..644665c136ca8 100644 --- a/tests/baselines/reference/parserharness.types +++ b/tests/baselines/reference/parserharness.types @@ -3931,9 +3931,9 @@ module Harness { if (!matchingIdentifiers.some(value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type))) { >!matchingIdentifiers.some(value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type)) : boolean >matchingIdentifiers.some(value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type)) : boolean ->matchingIdentifiers.some : (callbackfn: (value: Type, index: number, array: Type[]) => boolean, thisArg?: any) => boolean +>matchingIdentifiers.some : (callbackfn: (value: Type, index: number, array: Type[]) => {}, thisArg?: any) => boolean >matchingIdentifiers : Type[] ->some : (callbackfn: (value: Type, index: number, array: Type[]) => boolean, thisArg?: any) => boolean +>some : (callbackfn: (value: Type, index: number, array: Type[]) => {}, thisArg?: any) => boolean >value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type) : (value: Type) => boolean >value : Type >(value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type) : boolean @@ -4020,9 +4020,9 @@ module Harness { if (!matchingIdentifiers.some(value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type))) { >!matchingIdentifiers.some(value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type)) : boolean >matchingIdentifiers.some(value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type)) : boolean ->matchingIdentifiers.some : (callbackfn: (value: Type, index: number, array: Type[]) => boolean, thisArg?: any) => boolean +>matchingIdentifiers.some : (callbackfn: (value: Type, index: number, array: Type[]) => {}, thisArg?: any) => boolean >matchingIdentifiers : Type[] ->some : (callbackfn: (value: Type, index: number, array: Type[]) => boolean, thisArg?: any) => boolean +>some : (callbackfn: (value: Type, index: number, array: Type[]) => {}, thisArg?: any) => boolean >value => (value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type) : (value: Type) => boolean >value : Type >(value.identifier === foundValue.identifier) && (value.code === foundValue.code) && (value.type === foundValue.type) : boolean diff --git a/tests/baselines/reference/restInvalidArgumentType.types b/tests/baselines/reference/restInvalidArgumentType.types index ce59fb145f960..a3649e8880924 100644 --- a/tests/baselines/reference/restInvalidArgumentType.types +++ b/tests/baselines/reference/restInvalidArgumentType.types @@ -71,7 +71,7 @@ function f(p1: T, p2: T[]) { >p1 : T var {...r2} = p2; // OK ->r2 : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; pop(): T; push(...items: T[]): number; concat(...items: ConcatArray[]): T[]; concat(...items: (T | ConcatArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>r2 : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; pop(): T; push(...items: T[]): number; concat(...items: ConcatArray[]): T[]; concat(...items: (T | ConcatArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => {}, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => {}, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } >p2 : T[] var {...r3} = t; // Error, generic type paramter diff --git a/tests/baselines/reference/spreadInvalidArgumentType.types b/tests/baselines/reference/spreadInvalidArgumentType.types index 1acb22419a9cf..dde298050d9f8 100644 --- a/tests/baselines/reference/spreadInvalidArgumentType.types +++ b/tests/baselines/reference/spreadInvalidArgumentType.types @@ -73,8 +73,8 @@ function f(p1: T, p2: T[]) { >p1 : T var o2 = { ...p2 }; // OK ->o2 : { [x: number]: T; length: number; toString(): string; toLocaleString(): string; pop(): T; push(...items: T[]): number; concat(...items: ConcatArray[]): T[]; concat(...items: (T | ConcatArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } ->{ ...p2 } : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; pop(): T; push(...items: T[]): number; concat(...items: ConcatArray[]): T[]; concat(...items: (T | ConcatArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>o2 : { [x: number]: T; length: number; toString(): string; toLocaleString(): string; pop(): T; push(...items: T[]): number; concat(...items: ConcatArray[]): T[]; concat(...items: (T | ConcatArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => {}, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => {}, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>{ ...p2 } : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; pop(): T; push(...items: T[]): number; concat(...items: ConcatArray[]): T[]; concat(...items: (T | ConcatArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => {}, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => {}, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } >p2 : T[] var o3 = { ...t }; // Error, generic type paramter diff --git a/tests/baselines/reference/targetTypeArgs.types b/tests/baselines/reference/targetTypeArgs.types index 84985316aa2d6..5ed8746471ea6 100644 --- a/tests/baselines/reference/targetTypeArgs.types +++ b/tests/baselines/reference/targetTypeArgs.types @@ -31,11 +31,11 @@ foo(function(x) { x }); ["hello"].every(function(v,i,a) {return true;}); >["hello"].every(function(v,i,a) {return true;}) : boolean ->["hello"].every : (callbackfn: (value: string, index: number, array: string[]) => boolean, thisArg?: any) => boolean +>["hello"].every : (callbackfn: (value: string, index: number, array: string[]) => {}, thisArg?: any) => boolean >["hello"] : string[] >"hello" : "hello" ->every : (callbackfn: (value: string, index: number, array: string[]) => boolean, thisArg?: any) => boolean ->function(v,i,a) {return true;} : (v: string, i: number, a: string[]) => true +>every : (callbackfn: (value: string, index: number, array: string[]) => {}, thisArg?: any) => boolean +>function(v,i,a) {return true;} : (v: string, i: number, a: string[]) => boolean >v : string >i : number >a : string[] @@ -43,11 +43,11 @@ foo(function(x) { x }); [1].every(function(v,i,a) {return true;}); >[1].every(function(v,i,a) {return true;}) : boolean ->[1].every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean +>[1].every : (callbackfn: (value: number, index: number, array: number[]) => {}, thisArg?: any) => boolean >[1] : number[] >1 : 1 ->every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean ->function(v,i,a) {return true;} : (v: number, i: number, a: number[]) => true +>every : (callbackfn: (value: number, index: number, array: number[]) => {}, thisArg?: any) => boolean +>function(v,i,a) {return true;} : (v: number, i: number, a: number[]) => boolean >v : number >i : number >a : number[] @@ -55,11 +55,11 @@ foo(function(x) { x }); [1].every(function(v,i,a) {return true;}); >[1].every(function(v,i,a) {return true;}) : boolean ->[1].every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean +>[1].every : (callbackfn: (value: number, index: number, array: number[]) => {}, thisArg?: any) => boolean >[1] : number[] >1 : 1 ->every : (callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any) => boolean ->function(v,i,a) {return true;} : (v: number, i: number, a: number[]) => true +>every : (callbackfn: (value: number, index: number, array: number[]) => {}, thisArg?: any) => boolean +>function(v,i,a) {return true;} : (v: number, i: number, a: number[]) => boolean >v : number >i : number >a : number[] @@ -67,11 +67,11 @@ foo(function(x) { x }); ["s"].every(function(v,i,a) {return true;}); >["s"].every(function(v,i,a) {return true;}) : boolean ->["s"].every : (callbackfn: (value: string, index: number, array: string[]) => boolean, thisArg?: any) => boolean +>["s"].every : (callbackfn: (value: string, index: number, array: string[]) => {}, thisArg?: any) => boolean >["s"] : string[] >"s" : "s" ->every : (callbackfn: (value: string, index: number, array: string[]) => boolean, thisArg?: any) => boolean ->function(v,i,a) {return true;} : (v: string, i: number, a: string[]) => true +>every : (callbackfn: (value: string, index: number, array: string[]) => {}, thisArg?: any) => boolean +>function(v,i,a) {return true;} : (v: string, i: number, a: string[]) => boolean >v : string >i : number >a : string[] diff --git a/tests/cases/compiler/arrayEvery.ts b/tests/cases/compiler/arrayEvery.ts new file mode 100644 index 0000000000000..e506c76613781 --- /dev/null +++ b/tests/cases/compiler/arrayEvery.ts @@ -0,0 +1,18 @@ +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +const fizz = [ + { name: 'buzz' }, + { name: 'fizzbuzz' } +]; + +foo.every(x => {}); +foo.every(x => ""); +foo.every(x => { return; }); +foo.every(x => { return null; }); +foo.every(x => { return undefined; }); +foo.every(x => x.name); +fizz.every(x => x.name); \ No newline at end of file diff --git a/tests/cases/compiler/arrayFind.ts b/tests/cases/compiler/arrayFind.ts index 90883974766b7..6cfe25f9cbff3 100644 --- a/tests/cases/compiler/arrayFind.ts +++ b/tests/cases/compiler/arrayFind.ts @@ -10,3 +10,19 @@ const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(is const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); + + + +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; + +foo.find(x => {}); +foo.find(x => ""); +foo.find(x => { return; }); +foo.find(x => { return null; }); +foo.find(x => { return undefined; }); +foo.find(x => x.name); \ No newline at end of file diff --git a/tests/cases/compiler/arrayFindIndex.ts b/tests/cases/compiler/arrayFindIndex.ts new file mode 100644 index 0000000000000..cee4b3524f7a7 --- /dev/null +++ b/tests/cases/compiler/arrayFindIndex.ts @@ -0,0 +1,19 @@ +// @lib: es2015 + +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +const fizz = [ + { name: null } +]; + +foo.findIndex(x => {}); +foo.findIndex(x => ""); +foo.findIndex(x => { return; }); +foo.findIndex(x => { return null; }); +foo.findIndex(x => { return undefined; }); +foo.findIndex(x => x.name); +fizz.findIndex(x => x.name); \ No newline at end of file diff --git a/tests/cases/compiler/arraySome.ts b/tests/cases/compiler/arraySome.ts new file mode 100644 index 0000000000000..2277d34d94320 --- /dev/null +++ b/tests/cases/compiler/arraySome.ts @@ -0,0 +1,18 @@ +// Tests fix for #27496, predicates should not have to return booleans +const foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +const fizz = [ + { name: null }, + { name: null } +]; + +foo.some(x => {}); +foo.some(x => ""); +foo.some(x => { return; }); +foo.some(x => { return null; }); +foo.some(x => { return undefined; }); +foo.some(x => x.name); +fizz.some(x => x.name); \ No newline at end of file