-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix(ArrayBuffer): the ArrayBuffer constructor does not require an argument #53096
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
It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src/lib' or possibly our lib generator. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src/lib' or https://github.com/microsoft/TypeScript-DOM-lib-generator |
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
See also: #50657 (comment) Code like this only works because |
Whether it’s desirable or not doesn’t seem relevant - it’s how the language works. Arguments that can be omitted are optional, by definition. Note that I’m not trying to make it take an explicit undefined - i agree that that would be handling coercion behaviors - but an absent argument is different. |
This feels like a slippery slope. If I write the JS function function printNum(x) {
console.log(+x);
} or more to the point function makeBuf(sz) {
return new ArrayBuffer(sz);
} Let's assume the JS was written exactly like that and I'm now writing a corresponding |
I don't see the value of this change. A zero-length ArrayBuffer is useless; if you omitted this argument you've forgotten to do something important. It'd be like calling
The raison d'être of TypeScript is to identify undesirable code, regardless of whether or not the runtime behavior involves throwing an exception. "It happens to work at runtime" isn't the bar here. Even if we're deferring to the spec, the spec says this isn't optional either. The signature is
vs an optional parameter like
|
Fair enough, the spec saying it's required is pretty solid reasoning. Although if it was useless to have a zero byteLength then I assume you wouldn't be able to create one, so I don't buy that argument. |
new ArrayBuffer()
works fine and is the same asnew ArrayBuffer(0)
.