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

Update lib.d.ts: Change the type of uriComponent (passed to encodeURIComponent) from string to string | number | boolean #31103

Merged
merged 1 commit into from Apr 26, 2019

Conversation

smockle
Copy link
Member

@smockle smockle commented Apr 24, 2019

Fixes #18159



NB: This declaration also appears in lib/lib.es5.d.ts
https://github.com/Microsoft/TypeScript/blob/b0100100a18d740ad0b7c626bc81b800b5273ece/lib/lib.es5.d.ts#L83
…but I left that file alone per the instructions in “Contributing lib.d.ts fixes”.

@smockle smockle changed the title Change the type of uriComponent (passed to encodeURIComponent) from string to any Update lib.d.ts: Change the type of uriComponent (passed to encodeURIComponent) from string to any Apr 24, 2019
@treybrisbane
Copy link

Why not unknown?

@RyanCavanaugh
Copy link
Member

Consulting the spec here would lead you to believe that all functions should accept any, which is ultimately nihilistic.

Accepting string | number | boolean is much closer to representing the intended use cases.

@smockle
Copy link
Member Author

smockle commented Apr 26, 2019

Accepting string | number | boolean is much closer to representing the intended use cases.

Thanks for the guidance! I’ll update the PR.

@smockle smockle changed the title Update lib.d.ts: Change the type of uriComponent (passed to encodeURIComponent) from string to any Update lib.d.ts: Change the type of uriComponent (passed to encodeURIComponent) from string to string | number | boolean Apr 26, 2019
…om 'string' to 'string | number | boolean'. Fixes #18159

- According to the ECMAScript 5.1 spec (§15.1.3.4), 'encodeURIComponent' invokes the abstract operation 'ToString': https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4
- In the spec (§9.8), 'ToString' accepts an 'Undefined', 'Null', 'Boolean', 'Number', 'String' or 'Object' argument: https://www.ecma-international.org/ecma-262/5.1/#sec-9.8
- TypeScript’s 'StringConstructor' accepts an argument with type 'any': https://github.com/Microsoft/TypeScript/blob/b0100100a18d740ad0b7c626bc81b800b5273ece/lib/lib.es5.d.ts#L518
@RyanCavanaugh RyanCavanaugh merged commit d934401 into microsoft:master Apr 26, 2019
@RyanCavanaugh
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

encodeURIComponent should accept any value type
3 participants