Skip to content

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

Merged
RyanCavanaugh merged 1 commit into
microsoft:masterfrom
smockle:encodeURIComponent
Apr 26, 2019
Merged

Update lib.d.ts: Change the type of uriComponent (passed to encodeURIComponent) from string to string | number | boolean#31103
RyanCavanaugh merged 1 commit into
microsoft:masterfrom
smockle:encodeURIComponent

Conversation

@smockle
Copy link
Copy Markdown
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
Copy Markdown

Why not unknown?

@RyanCavanaugh
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Thanks!

@smockle smockle deleted the encodeURIComponent branch April 26, 2019 20:34
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
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.

encodeURIComponent should accept any value type

3 participants