From 52dd84fc8737068560e47ed8770d9cdc2a864f8a Mon Sep 17 00:00:00 2001 From: NimaZahedi Date: Sat, 2 Apr 2016 00:14:26 +0200 Subject: [PATCH 1/4] Add test for issue --- tests/cases/compiler/arrayFilter.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/cases/compiler/arrayFilter.ts diff --git a/tests/cases/compiler/arrayFilter.ts b/tests/cases/compiler/arrayFilter.ts new file mode 100644 index 0000000000000..d13dc0dc9faec --- /dev/null +++ b/tests/cases/compiler/arrayFilter.ts @@ -0,0 +1,7 @@ +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +] + +foo.filter(x => x.name); //should accepted all possible types not only boolean! \ No newline at end of file From 75ad5e5d8e8cca63744296f0d08df4a3f2123dd7 Mon Sep 17 00:00:00 2001 From: NimaZahedi Date: Sat, 2 Apr 2016 00:24:49 +0200 Subject: [PATCH 2/4] Fix issue --- src/lib/es5.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 65f4fbabf6b7b..ef8d4620301ac 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1510,7 +1510,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. */ - filter(callbackfn: (value: number, index: number, array: Int8Array) => boolean, thisArg?: any): Int8Array; + filter(callbackfn: (value: number, index: number, array: Int8Array) => any, thisArg?: any): Int8Array; /** * Returns the value of the first element in the array where predicate is true, and undefined From 39c0d3db63269291e525420f8f11d2b19dbb6efe Mon Sep 17 00:00:00 2001 From: NimaZahedi Date: Sat, 2 Apr 2016 01:03:51 +0200 Subject: [PATCH 3/4] Add baselines --- tests/baselines/reference/arrayFilter.errors.txt | 15 +++++++++++++++ tests/baselines/reference/arrayFilter.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/baselines/reference/arrayFilter.errors.txt create mode 100644 tests/baselines/reference/arrayFilter.js diff --git a/tests/baselines/reference/arrayFilter.errors.txt b/tests/baselines/reference/arrayFilter.errors.txt new file mode 100644 index 0000000000000..f71a9a95980cc --- /dev/null +++ b/tests/baselines/reference/arrayFilter.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/arrayFilter.ts(7,12): error TS2345: Argument of type '(x: { name: string; }) => string' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => boolean'. + Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/compiler/arrayFilter.ts (1 errors) ==== + var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } + ] + + foo.filter(x => x.name); //should accepted all possible types not only boolean! + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: { name: string; }) => string' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => boolean'. +!!! error TS2345: Type 'string' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayFilter.js b/tests/baselines/reference/arrayFilter.js new file mode 100644 index 0000000000000..dd3b321b19ced --- /dev/null +++ b/tests/baselines/reference/arrayFilter.js @@ -0,0 +1,16 @@ +//// [arrayFilter.ts] +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +] + +foo.filter(x => x.name); //should accepted all possible types not only boolean! + +//// [arrayFilter.js] +var foo = [ + { name: 'bar' }, + { name: null }, + { name: 'baz' } +]; +foo.filter(function (x) { return x.name; }); //should accepted all possible types not only boolean! From fcf0be11ce71a483f112fb046da0d62fb3774ed5 Mon Sep 17 00:00:00 2001 From: NimaZahedi Date: Fri, 15 Apr 2016 15:23:11 +0200 Subject: [PATCH 4/4] fix issue --- src/lib/es5.d.ts | 20 +++++------ .../reference/arrayFilter.errors.txt | 15 --------- tests/baselines/reference/arrayFilter.symbols | 24 ++++++++++++++ tests/baselines/reference/arrayFilter.types | 33 +++++++++++++++++++ .../genericMethodOverspecialization.types | 4 +-- 5 files changed, 69 insertions(+), 27 deletions(-) delete mode 100644 tests/baselines/reference/arrayFilter.errors.txt create mode 100644 tests/baselines/reference/arrayFilter.symbols create mode 100644 tests/baselines/reference/arrayFilter.types diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index ef8d4620301ac..4e292dd7a8330 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1061,7 +1061,7 @@ interface ReadonlyArray { * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in 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. */ - filter(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): T[]; + filter(callbackfn: (value: T, index: number, array: ReadonlyArray) => any, thisArg?: any): T[]; /** * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @@ -1196,7 +1196,7 @@ interface Array { * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in 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. */ - filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[]; + filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; /** * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @@ -1783,7 +1783,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. */ - filter(callbackfn: (value: number, index: number, array: Uint8Array) => boolean, thisArg?: any): Uint8Array; + filter(callbackfn: (value: number, index: number, array: Uint8Array) => any, thisArg?: any): Uint8Array; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -2057,7 +2057,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. */ - filter(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => boolean, thisArg?: any): Uint8ClampedArray; + filter(callbackfn: (value: number, index: number, array: Uint8ClampedArray) => any, thisArg?: any): Uint8ClampedArray; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -2330,7 +2330,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. */ - filter(callbackfn: (value: number, index: number, array: Int16Array) => boolean, thisArg?: any): Int16Array; + filter(callbackfn: (value: number, index: number, array: Int16Array) => any, thisArg?: any): Int16Array; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -2604,7 +2604,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. */ - filter(callbackfn: (value: number, index: number, array: Uint16Array) => boolean, thisArg?: any): Uint16Array; + filter(callbackfn: (value: number, index: number, array: Uint16Array) => any, thisArg?: any): Uint16Array; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -2877,7 +2877,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. */ - filter(callbackfn: (value: number, index: number, array: Int32Array) => boolean, thisArg?: any): Int32Array; + filter(callbackfn: (value: number, index: number, array: Int32Array) => any, thisArg?: any): Int32Array; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -3150,7 +3150,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. */ - filter(callbackfn: (value: number, index: number, array: Uint32Array) => boolean, thisArg?: any): Uint32Array; + filter(callbackfn: (value: number, index: number, array: Uint32Array) => any, thisArg?: any): Uint32Array; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -3423,7 +3423,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. */ - filter(callbackfn: (value: number, index: number, array: Float32Array) => boolean, thisArg?: any): Float32Array; + filter(callbackfn: (value: number, index: number, array: Float32Array) => any, thisArg?: any): Float32Array; /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -3697,7 +3697,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. */ - filter(callbackfn: (value: number, index: number, array: Float64Array) => boolean, thisArg?: any): Float64Array; + filter(callbackfn: (value: number, index: number, array: Float64Array) => any, thisArg?: any): Float64Array; /** * Returns the value of the first element in the array where predicate is true, and undefined diff --git a/tests/baselines/reference/arrayFilter.errors.txt b/tests/baselines/reference/arrayFilter.errors.txt deleted file mode 100644 index f71a9a95980cc..0000000000000 --- a/tests/baselines/reference/arrayFilter.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/arrayFilter.ts(7,12): error TS2345: Argument of type '(x: { name: string; }) => string' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => boolean'. - Type 'string' is not assignable to type 'boolean'. - - -==== tests/cases/compiler/arrayFilter.ts (1 errors) ==== - var foo = [ - { name: 'bar' }, - { name: null }, - { name: 'baz' } - ] - - foo.filter(x => x.name); //should accepted all possible types not only boolean! - ~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: { name: string; }) => string' is not assignable to parameter of type '(value: { name: string; }, index: number, array: { name: string; }[]) => boolean'. -!!! error TS2345: Type 'string' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayFilter.symbols b/tests/baselines/reference/arrayFilter.symbols new file mode 100644 index 0000000000000..fcdd39117a73e --- /dev/null +++ b/tests/baselines/reference/arrayFilter.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/arrayFilter.ts === +var foo = [ +>foo : Symbol(foo, Decl(arrayFilter.ts, 0, 3)) + + { name: 'bar' }, +>name : Symbol(name, Decl(arrayFilter.ts, 1, 5)) + + { name: null }, +>name : Symbol(name, Decl(arrayFilter.ts, 2, 5)) + + { name: 'baz' } +>name : Symbol(name, Decl(arrayFilter.ts, 3, 5)) + +] + +foo.filter(x => x.name); //should accepted all possible types not only boolean! +>foo.filter : Symbol(Array.filter, Decl(lib.d.ts, --, --)) +>foo : Symbol(foo, Decl(arrayFilter.ts, 0, 3)) +>filter : Symbol(Array.filter, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(arrayFilter.ts, 6, 11)) +>x.name : Symbol(name, Decl(arrayFilter.ts, 1, 5)) +>x : Symbol(x, Decl(arrayFilter.ts, 6, 11)) +>name : Symbol(name, Decl(arrayFilter.ts, 1, 5)) + diff --git a/tests/baselines/reference/arrayFilter.types b/tests/baselines/reference/arrayFilter.types new file mode 100644 index 0000000000000..f3d6d42174494 --- /dev/null +++ b/tests/baselines/reference/arrayFilter.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/arrayFilter.ts === +var foo = [ +>foo : { name: string; }[] +>[ { name: 'bar' }, { name: null }, { name: 'baz' }] : { name: string; }[] + + { name: 'bar' }, +>{ name: 'bar' } : { name: string; } +>name : string +>'bar' : string + + { name: null }, +>{ name: null } : { name: null; } +>name : null +>null : null + + { name: 'baz' } +>{ name: 'baz' } : { name: string; } +>name : string +>'baz' : string + +] + +foo.filter(x => x.name); //should accepted all possible types not only boolean! +>foo.filter(x => x.name) : { name: string; }[] +>foo.filter : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => any, thisArg?: any) => { name: string; }[] +>foo : { name: string; }[] +>filter : (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => any, thisArg?: any) => { name: string; }[] +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + diff --git a/tests/baselines/reference/genericMethodOverspecialization.types b/tests/baselines/reference/genericMethodOverspecialization.types index 0ad302da94e9e..375eefaa86cb3 100644 --- a/tests/baselines/reference/genericMethodOverspecialization.types +++ b/tests/baselines/reference/genericMethodOverspecialization.types @@ -53,9 +53,9 @@ var elements = names.map(function (name) { var xxx = elements.filter(function (e) { >xxx : HTMLElement[] >elements.filter(function (e) { return !e.isDisabled;}) : HTMLElement[] ->elements.filter : (callbackfn: (value: HTMLElement, index: number, array: HTMLElement[]) => boolean, thisArg?: any) => HTMLElement[] +>elements.filter : (callbackfn: (value: HTMLElement, index: number, array: HTMLElement[]) => any, thisArg?: any) => HTMLElement[] >elements : HTMLElement[] ->filter : (callbackfn: (value: HTMLElement, index: number, array: HTMLElement[]) => boolean, thisArg?: any) => HTMLElement[] +>filter : (callbackfn: (value: HTMLElement, index: number, array: HTMLElement[]) => any, thisArg?: any) => HTMLElement[] >function (e) { return !e.isDisabled;} : (e: HTMLElement) => boolean >e : HTMLElement