Skip to content

Array.prototype.filter.not.forcing.boolean.type #7776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/arrayFilter.errors.txt
Original file line number Diff line number Diff line change
@@ -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'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this error doing here? It seems like this baseline file shouldn't exist.

The correct order of operations is:

  • Make your change
  • jake runtests
  • jake baseline-accept
  • jake runtests (this should always pass)
  • Then commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I though this file should be part of my commit as well! Thanks 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RyanCavanaugh btw, I made another branch and did exactly the flow that you said ^^, I run jake runtests for second time and it was passed, but still there was that file(arrayFilter.errors.txt) in my git which I thought should be part of my commit! anyway, I commit without that! but I want to know is it correct?! I mean shouldn't be deleted by jake runtests!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RyanCavanaugh in the managing the baselines said, these files should be part of the commit 😕

!!! error TS2345: Type 'string' is not assignable to type 'boolean'.
16 changes: 16 additions & 0 deletions tests/baselines/reference/arrayFilter.js
Original file line number Diff line number Diff line change
@@ -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!
7 changes: 7 additions & 0 deletions tests/cases/compiler/arrayFilter.ts
Original file line number Diff line number Diff line change
@@ -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!