microsoft / TypeScript-DOM-lib-generator

Tool for generating dom related TypeScript and JavaScript library files
Apache License 2.0
600 stars 417 forks source link

`String.prototype.charCodeAt` accepts `undefined` #1707

Closed mollthecoder closed 2 months ago

mollthecoder commented 2 months ago

Take the following example:

"Hello, world!".charCodeAt();

This is safe, because undefined is automatically converted to zero. It is equivalent to this:

"Hello, world!".charCodeAt(0);

Or this:

"H".charCodeAt(0);

However, it is currently marked as a required argument.

HolgerJeromin commented 2 months ago

Would that change be only spec conform or really useful? I think many/some calls with variables with undefined are bugs/unintentional.

saschanaz commented 2 months ago

This should go https://github.com/microsoft/TypeScript as the code resides there.

RyanCavanaugh commented 2 months ago

This is the intended behavior.