-
Notifications
You must be signed in to change notification settings - Fork 13.2k
fix: add generic info for methods with thisArg of built-in classes #12784
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
Conversation
|
Hi @e-cloud, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
|
@DanielRosenwasser @mhegazy can you have a review and give some guide on how to write corresponding tests? |
|
Hi, I am closing and re-opening this PR to bump the CLA bot. Sorry for the inconvenience! |
|
Hi @e-cloud, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
|
@mhegazy can you take a review? |
|
The change looks good. To write tests, add a file named something like Run After you get that workflow going, you should add tests for all the functions you improved too. |
4339c9a to
c42a029
Compare
|
@sandersn, new test is added. And i find out the new version of tslint breaks down the linting task. |
| options.every(function (val, index) { | ||
| return val === this.options[index]; | ||
| }, this); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also add tests for ReadonlyArray and the other U?.*Array types?
| } | ||
|
|
||
| test(options: string[]) { | ||
| options.some(function (val, index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add tests for find, findIndex, forEach, map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that it would be problem. As the default compile target seems to be es5. Then it prompts that find not exist in xxx[]. Should we create a test project for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change the target with a line at the beginning: // @target: es6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your guidance is helpful
sandersn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests for the other array methods and array types?
|
should not this be two overloads: find(predicate: (this: undefined, value: T, index: number, obj: Array<T>) => boolean): T | undefined;
find<U>(predicate: (this: U, value: T, index: number, obj: Array<T>) => boolean, thisArg : U): T | undefined; the spec seems to indicate that, here is what MDN has to say: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find |
|
Also there are other find functions for TypedArrays that should be updated as well.. e.g. |
|
@mhegazy what do you mean by:
Can you describe it more clearly? |
|
From MDN:
if |
|
@mhegazy I see what you mean now. I have some tries and find out some problems. TL;DRUse the class A {
options: string[];
addOptions(options: string[]) {
if (!this.options) {
this.options = [];
}
options.forEach(function (item) {
this.options.push(item);
}, this);
return this;
}
testUndefined(options: string[]) {
options.forEach(function (item) {
this.options.push(item);
}); // case1
options.forEach(function (item) {
this.options.push(item);
}, undefined); // case2
options.forEach(function (item) {
this.options.push(item);
}, null); // case3
}
}in
forEach(callbackfn: (this: undefined, value: T, index: number, array: T[]) => void): void;
forEach<Z>(callbackfn: (this: Z, value: T, index: number, array: T[]) => void, thisArg: Z): void;erros from only
forEach(callbackfn: (this: undefined, value: T, index: number, array: T[]) => void): void;
forEach(callbackfn: (this: undefined, value: T, index: number, array: T[]) => void, thisArg: undefined): void;
forEach<Z>(callbackfn: (this: Z, value: T, index: number, array: T[]) => void, thisArg: Z): void;erros from now all are recognized as undefined, even
forEach(callbackfn: (this: undefined, value: T, index: number, array: T[]) => void): void;
forEach(callbackfn: (this: null, value: T, index: number, array: T[]) => void, thisArg: null): void;
forEach(callbackfn: (this: undefined, value: T, index: number, array: T[]) => void, thisArg: undefined): void;
forEach<Z>(callbackfn: (this: Z, value: T, index: number, array: T[]) => void, thisArg: Z): void;erros from It seems the nulled-this interface takes precedence. And if the In short
Personally, I'm ok with version 2 for temporary solution. @mhegazy do you agree to make three interfaces for all involved methods? |
|
Another thing worths mentioning is that the |
c42a029 to
6872883
Compare
|
Note that option 1 works correctly with |
|
@sandersn It seems to fail many tests. Should I update the other baseline files? It would be a lot of files. |
|
Yes, the baseline changes are expected: when you add overloads, it changes the symbols and types to reflect those additional overloads, even if the types resulting from the call doesn't change. |
b046380 to
b6998a4
Compare
b6998a4 to
4756b6a
Compare
|
@mhegazy request for review |
|
You have a |
|
Yes, accident. 😭 |
4756b6a to
222b828
Compare
222b828 to
5c26e62
Compare
when enabling `noImplicitThis`, if assing this argument for methods like `array.forEach` will cause compilation error. This commit fixes it. fix microsoft#12548
5c26e62 to
1b7c11a
Compare
|
@sandersn ,I've rebased on master just now. Can you guys give some review and feedback? Coz it's been a while since starting the PR. The tests failed because of the latest problematic |
|
I have a fix in master now for the build break. can you give it another try. |
1b7c11a to
09fcf5b
Compare
|
tests pass now. |
|
Thanks @e-cloud! |
Here's a checklist you might find useful.
'Bug' or 'Accepting PRs' or is in the Community milestone
masterbranchjake runtestslocallyFixes #12548
Note: need guide to write tests