Skip to content

Commit d934401

Browse files
smockleRyanCavanaugh
authored andcommitted
Change the type of 'uriComponent' (passed to 'encodeURIComponent') from 'string' to 'string | number | boolean'. Fixes #18159 (#31103)
- 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
1 parent 94ee0dc commit d934401

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

src/lib/es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare function encodeURI(uri: string): string;
6060
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
6161
* @param uriComponent A value representing an encoded URI component.
6262
*/
63-
declare function encodeURIComponent(uriComponent: string): string;
63+
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
6464

6565
/**
6666
* Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.

tests/baselines/reference/1.0lib-noErrors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ declare function encodeURI(uri: string): string;
7878
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
7979
* @param uriComponent A value representing an encoded URI component.
8080
*/
81-
declare function encodeURIComponent(uriComponent: string): string;
81+
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
8282

8383
interface PropertyDescriptor {
8484
configurable?: boolean;
@@ -1141,7 +1141,7 @@ declare var Array: {
11411141
<T>(...items: T[]): T[];
11421142
isArray(arg: any): boolean;
11431143
prototype: Array<any>;
1144-
}
1144+
}
11451145

11461146
//// [1.0lib-noErrors.js]
11471147
/* *****************************************************************************

tests/baselines/reference/1.0lib-noErrors.symbols

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ declare function encodeURI(uri: string): string;
9898
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
9999
* @param uriComponent A value representing an encoded URI component.
100100
*/
101-
declare function encodeURIComponent(uriComponent: string): string;
101+
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
102102
>encodeURIComponent : Symbol(encodeURIComponent, Decl(1.0lib-noErrors.ts, 73, 48))
103103
>uriComponent : Symbol(uriComponent, Decl(1.0lib-noErrors.ts, 79, 36))
104104

105105
interface PropertyDescriptor {
106-
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
106+
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))
107107

108108
configurable?: boolean;
109109
>configurable : Symbol(PropertyDescriptor.configurable, Decl(1.0lib-noErrors.ts, 81, 30))
@@ -130,7 +130,7 @@ interface PropertyDescriptorMap {
130130

131131
[s: string]: PropertyDescriptor;
132132
>s : Symbol(s, Decl(1.0lib-noErrors.ts, 91, 5))
133-
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
133+
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))
134134
}
135135

136136
interface Object {
@@ -217,7 +217,7 @@ declare var Object: {
217217
>getOwnPropertyDescriptor : Symbol(getOwnPropertyDescriptor, Decl(1.0lib-noErrors.ts, 141, 32))
218218
>o : Symbol(o, Decl(1.0lib-noErrors.ts, 149, 29))
219219
>p : Symbol(p, Decl(1.0lib-noErrors.ts, 149, 36))
220-
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
220+
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))
221221

222222
/**
223223
* Returns the names of the own properties of an object. The own properties of an object are those that are defined directly
@@ -250,7 +250,7 @@ declare var Object: {
250250
>o : Symbol(o, Decl(1.0lib-noErrors.ts, 171, 19))
251251
>p : Symbol(p, Decl(1.0lib-noErrors.ts, 171, 26))
252252
>attributes : Symbol(attributes, Decl(1.0lib-noErrors.ts, 171, 37))
253-
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66))
253+
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85))
254254

255255
/**
256256
* Adds one or more properties to an object, and/or modifies attributes of existing properties.
@@ -2084,3 +2084,4 @@ declare var Array: {
20842084
>prototype : Symbol(prototype, Decl(1.0lib-noErrors.ts, 1140, 31))
20852085
>Array : Symbol(Array, Decl(1.0lib-noErrors.ts, 973, 23), Decl(1.0lib-noErrors.ts, 1133, 11))
20862086
}
2087+

tests/baselines/reference/1.0lib-noErrors.types

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ declare function encodeURI(uri: string): string;
9898
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
9999
* @param uriComponent A value representing an encoded URI component.
100100
*/
101-
declare function encodeURIComponent(uriComponent: string): string;
102-
>encodeURIComponent : (uriComponent: string) => string
103-
>uriComponent : string
101+
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
102+
>encodeURIComponent : (uriComponent: string | number | boolean) => string
103+
>uriComponent : string | number | boolean
104104

105105
interface PropertyDescriptor {
106106
configurable?: boolean;
@@ -1911,3 +1911,4 @@ declare var Array: {
19111911
prototype: Array<any>;
19121912
>prototype : any[]
19131913
}
1914+

tests/baselines/reference/parserRegularExpression4.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (Ca.test(c.href) || Ba.test(c.href) && /(\\?|&)adurl=/.test(c.href) && !/(\\?
6161
>"&q=" + encodeURIComponent(W("q") || W("as_q") || A) : string
6262
>"&q=" : "&q="
6363
>encodeURIComponent(W("q") || W("as_q") || A) : string
64-
>encodeURIComponent : (uriComponent: string) => string
64+
>encodeURIComponent : (uriComponent: string | number | boolean) => string
6565
>W("q") || W("as_q") || A : any
6666
>W("q") || W("as_q") : any
6767
>W("q") : any

tests/cases/conformance/decorators/1.0lib-noErrors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ declare function encodeURI(uri: string): string;
7878
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
7979
* @param uriComponent A value representing an encoded URI component.
8080
*/
81-
declare function encodeURIComponent(uriComponent: string): string;
81+
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
8282

8383
interface PropertyDescriptor {
8484
configurable?: boolean;
@@ -1141,4 +1141,4 @@ declare var Array: {
11411141
<T>(...items: T[]): T[];
11421142
isArray(arg: any): boolean;
11431143
prototype: Array<any>;
1144-
}
1144+
}

tests/lib/lib.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ declare function encodeURI(uri: string): string;
7777
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
7878
* @param uriComponent A value representing an encoded URI component.
7979
*/
80-
declare function encodeURIComponent(uriComponent: string): string;
80+
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
8181

8282
/**
8383
* Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.

0 commit comments

Comments
 (0)