Uh oh!
There was an error while loading. Please reload this page.
fix: add generic info for methods with thisArg of built-in classes - #12784
Conversation
Hi Scott (@e-cloud), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
Daniel Rosenwasser (@DanielRosenwasser)Mohamed Hegazy (@mhegazy) can you have a review and give some guide on how to write corresponding tests? |
Microsoft GitHub User (msftgits)
commented
Dec 9, 2016
Hi, I am closing and re-opening this PR to bump the CLA bot. Sorry for the inconvenience! |
Hi Scott (@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; |
Scott (e-cloud)
commented
Dec 15, 2016
Mohamed Hegazy (@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
c42a029CompareScott (e-cloud)
commented
Dec 17, 2016
Nathan Shively-Sanders (@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.
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.
can you also add tests for find, findIndex, forEach, map?
There was a problem hiding this comment.
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.
You can change the target with a line at the beginning: // @target: es6
There was a problem hiding this comment.
your guidance is helpful
Nathan Shively-Sanders (sandersn)
left a comment
There was a problem hiding this comment.
Can you add tests for the other array methods and array types?
Mohamed Hegazy (mhegazy)
commented
Dec 22, 2016
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 |
Mohamed Hegazy (mhegazy)
commented
Dec 22, 2016
Also there are other find functions for TypedArrays that should be updated as well.. e.g. |
Scott (e-cloud)
commented
Dec 22, 2016
Mohamed Hegazy (@mhegazy) what do you mean by:
Can you describe it more clearly? |
Mohamed Hegazy (mhegazy)
commented
Dec 22, 2016
From MDN:
if |
Mohamed Hegazy (@mhegazy) I see what you mean now. I have some tries and find out some problems. TL;DRUse the classA{options: string[];addOptions(options: string[]){if(!this.options){this.options=[];}options.forEach(function(item){this.options.push(item);},this);returnthis;}testUndefined(options: string[]){options.forEach(function(item){this.options.push(item);});// case1options.forEach(function(item){this.options.push(item);},undefined);// case2options.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. Mohamed Hegazy (@mhegazy) do you agree to make three interfaces for all involved methods? |
Scott (e-cloud)
commented
Dec 24, 2016
Another thing worths mentioning is that the |
c42a029 to
6872883CompareScott (e-cloud)
commented
Jan 5, 2017
Mohamed Hegazy (@mhegazy)Nathan Shively-Sanders (@sandersn) I've rewrite the PR to accomplish the solution commented above. Note: I use several regexps to globally update the interfaces. Manually updating per interface would be nightmare. |
Nathan Shively-Sanders (sandersn)
commented
Jan 5, 2017
Note that option 1 works correctly with |
Scott (e-cloud)
commented
Jan 6, 2017
Nathan Shively-Sanders (@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
b6998a4CompareScott (e-cloud)
commented
Jan 11, 2017
Mohamed Hegazy (@mhegazy)Nathan Shively-Sanders (@sandersn) hey, guys. All checks have passed now. How about have a review again? |
b6998a4 to
4756b6aCompareScott (e-cloud)
commented
Jan 24, 2017
Mohamed Hegazy (@mhegazy) request for review |
Ali Taheri Moghaddar (alitaheri)
commented
Jan 24, 2017
You have a |
Yes, accident. 😭 |
4756b6a to
222b828Compare222b828 to
5c26e62Comparewhen enabling `noImplicitThis`, if assing this argument for methods like `array.forEach` will cause compilation error. This commit fixes it. fixmicrosoft#12548
5c26e62 to
1b7c11aCompareScott (e-cloud)
commented
Mar 9, 2017
Nathan Shively-Sanders (@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 |
Mohamed Hegazy (mhegazy)
commented
Mar 9, 2017
I have a fix in master now for the build break. can you give it another try. |
1b7c11a to
09fcf5bCompareScott (e-cloud)
commented
Mar 10, 2017
tests pass now. |
Thanks Scott (@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