Skip to content
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

make splice deleteCount required in es5.d.ts #32643

Merged
merged 3 commits into from
Mar 12, 2020

Conversation

tjenkinson
Copy link
Contributor

@tjenkinson tjenkinson commented Jul 31, 2019

In ES5 deleteCount is not an optional argument. If it is not provided it defaults to 0 as a side effect of undefined being converted to an integer.
https://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.12

In ES6 deleleteCount is optional, and it defaults to the length of the array minus the start index.
https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.splice

If you are targeting ES5 but don't provide deleteCount the behaviour will be different depending on the environment your build is running in.

This PR makes the deleteCount required when targeting ES5 but should allow it to be optional for ES6.

fixes #32638

The Issue

When running in ES5

const input = [1, 2, 3];
const out = in.splice(0);
console.log(input); // [1, 2, 3]
console.log(out); // []

When running in ES6

const input = [1, 2, 3];
const out = in.splice(0);
console.log(input); // []
console.log(out); // [1, 2, 3]

@msftclas
Copy link

msftclas commented Jul 31, 2019

CLA assistant check
All CLA requirements met.

In ES5 `deleteCount` is not an optional argument. If it is not provided it defaults to 0 as a side effect of `undefined` being converted to an integer.

In ES6 `deleleteCount` is optional, and it defaults to the length of the array minus the start index.

If you are targeting ES5 but don't provide `deleteCount` the behaviour will be different depending on the environment your build is running in.

fixes microsoft#32638
@RyanCavanaugh
Copy link
Member

@typescript-bot test this
@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 31, 2019

Heya @RyanCavanaugh, I've started to run the parallelized community code test suite on this PR at 368d007. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

Heya @RyanCavanaugh, I'm starting to run the extended test suite on this PR at 368d007. Hold tight - I'll update this comment with the log link once the build has been queued.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@RyanCavanaugh
Copy link
Member

@weswigham looks like some noise in the user suite diff - can you check in on it?

@weswigham
Copy link
Member

I opened #32610 to fix the chrome devtools changes awhile ago, the other changes (to the azure sdk which is happily updating rush and such under us, and to zone.js which seems to be broken slightly (no ides if that's our fault)) just need to be accepted.

@tjenkinson
Copy link
Contributor Author

Anything I can do to help here?

@tjenkinson
Copy link
Contributor Author

tjenkinson commented Jan 17, 2020

@RyanCavanaugh @weswigham any update?

@sandersn sandersn added this to Curio in Pall Mall Jan 30, 2020
@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 1, 2020
@sandersn sandersn added this to Needs merge in PR Backlog Mar 9, 2020
@sandersn sandersn removed this from Curio in Pall Mall Mar 9, 2020
@tjenkinson
Copy link
Contributor Author

I brought this back up to date with master

@sandersn
Copy link
Member

Thanks for your patience on this!

@sandersn sandersn merged commit ddcf139 into microsoft:master Mar 12, 2020
PR Backlog automation moved this from Needs merge to Done Mar 12, 2020
@RyanCavanaugh
Copy link
Member

This caused a break

const arr: string[] = [];
const boundSplice = arr.splice.bind(arr, 0, 0);
const items: string[] = [];
// Used to be OK, now an error
boundSplice.apply(arr, items);

@ljharb
Copy link
Contributor

ljharb commented Apr 24, 2020

@RyanCavanaugh it's OK in ES6, it's not OK in ES5 (altho there may have been pre-ES6 browsers that considered it optional). is that a type error when targeting ES6?

@RyanCavanaugh
Copy link
Member

It's incorrectly a type error right now against ES6

@tjenkinson
Copy link
Contributor Author

tjenkinson commented Apr 24, 2020

Shame this is getting reverted. We had an outage on our TV app which this would have caught if it had existed. A few TV’s are still way back in the past.

@tjenkinson
Copy link
Contributor Author

Do you know why it caused bind and apply to break?

@ljharb
Copy link
Contributor

ljharb commented Apr 24, 2020

@RyanCavanaugh so does that mean this PR needed to also override it in ES6 to make it optional?

@DanielRosenwasser
Copy link
Member

@tjenkinson I believe it's because under strictBindCallApply, we try to infer the types from the signature, but overloads don't play well with that functionality. So @ljharb, if you had ES6 as the target, that extra overload caused issues. We believe that the most reasonable solution is to just say it's optional.

@tjenkinson
Copy link
Contributor Author

Ok thanks for the explanation.

It’s a shame but not the end of the world because es5-shim protects us now :). I guess we could also add the definition to our projects manually.

@ljharb
Copy link
Contributor

ljharb commented Apr 24, 2020

@DanielRosenwasser it seems like fixing the underlying flaws with overloads is a pretty important thing to address :-/

@DanielRosenwasser
Copy link
Member

I agree, but I don't think we have anything concrete that we feel good about yet.

DanielRosenwasser added a commit that referenced this pull request Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

deleteCount param to splice() is not optional in es5 types
8 participants