Skip to content

Conversation

@Arnavion
Copy link
Contributor

  1. Array, TypedArray, Map and Set methods that are specced to return the this-object now return this instead of explicit type.
  2. The callbacks in Array, TypedArray, Map and Set methods that pass the this-object to that callback now pass this instead of explicit type.
  3. Added an overload for ES6 String.normalize's that has form parameter as union of the allowed string literals.

tests/cases/compiler/implementArrayInterface started failing until I updated it, since it is now an error to implement array methods with old callback that accepted T[]. Breaking change?

tests/cases/compiler/duplicateOverloadInTypeAugmentation still passed (with just baseline update for the types). But I've changed the overloads it defines from T[] to this anyway.

jake runtests passes.

* @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<T>) => boolean, thisArg?: any): boolean;
some(callbackfn: (value: T, index: number, array: this) => boolean, thisArg?: any): boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is going to be a breaking change, and not sure it adds much value here.

Copy link
Contributor

Choose a reason for hiding this comment

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

//CC @RyanCavanaugh, thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean just for ReadOnlyArray or all of them?

Copy link
Contributor

Choose a reason for hiding this comment

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

i mean the use of this type in the call back argument type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm asking if it's a problem just for ReadOnlyArray or all the other Array classes as well where I did the same change?

Copy link

Choose a reason for hiding this comment

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

Impact is very low because support for fully subclassing Array is very recent and narrow (stable: only Edge). See Kangax:
http://kangax.github.io/compat-table/es6/#test-Array_is_subclassable_Array.prototype.filter

Only people who subclass Array and override one of those methods with callbacks (find, some, etc.) are impacted.

But in the future you can expect several frameworks to "hack" arrays for their own special purposes... At which point the annotation will become a tiny bit relevant (only a tiny bit because I never see the third parameter used in practice).

I will also say that TS has had breaking changes by way of tightening its type checks or fixing incorrect declarations at several occasions in the past.

I'd say: now is the right time for the change -- otherwise never.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for the delay. i meant all of them.

@Arnavion
Copy link
Contributor Author

(I can update this PR for the es6.d.ts split in master once I get confirmation for mhegazy's comment.)

@mhegazy
Copy link
Contributor

mhegazy commented May 7, 2016

sorry for they delay. if you can update the PR with the new file structure that would be great. thanks!

@Arnavion
Copy link
Contributor Author

Arnavion commented May 7, 2016

So you don't want the change to make the callbacks have a this parameter right? i.e. you don't want the changes in the second and fourth commits?

@Arnavion
Copy link
Contributor Author

Arnavion commented May 7, 2016

See #8515

@mhegazy
Copy link
Contributor

mhegazy commented May 9, 2016

thanks!. do we still need this one then after #8515 is merged.

@Arnavion
Copy link
Contributor Author

Arnavion commented May 9, 2016

No.

@Arnavion Arnavion closed this May 9, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants