Skip to content

add toString definitions for base types that have them #37839

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ declare var String: StringConstructor;
interface Boolean {
/** Returns the primitive value of the specified object. */
valueOf(): boolean;
/** Returns a string representation of a boolean. */
toString(): string;
}

interface BooleanConstructor {
Expand Down Expand Up @@ -925,6 +927,9 @@ interface RegExp {

// Non-standard extensions
compile(): this;

/** Returns a string representation of a regular expression. */
toString(): string;
}

interface RegExpConstructor {
Expand Down Expand Up @@ -953,6 +958,8 @@ interface Error {
name: string;
message: string;
stack?: string;
/** Returns a string representation of an Error object. */
toString(): string;
}

interface ErrorConstructor {
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/booleanPropertyAccess.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ var x = true;

var a = x.toString();
>a : Symbol(a, Decl(booleanPropertyAccess.ts, 2, 3))
>x.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>x.toString : Symbol(Boolean.toString, Decl(lib.es5.d.ts, --, --))
>x : Symbol(x, Decl(booleanPropertyAccess.ts, 0, 3))
>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>toString : Symbol(Boolean.toString, Decl(lib.es5.d.ts, --, --))

var b = x['toString']();
>b : Symbol(b, Decl(booleanPropertyAccess.ts, 3, 3))
>x : Symbol(x, Decl(booleanPropertyAccess.ts, 0, 3))
>'toString' : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>'toString' : Symbol(Boolean.toString, Decl(lib.es5.d.ts, --, --))

Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ module TypeScriptAllInOne {
>float2.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>float2 : Symbol(float2, Decl(constructorWithIncompleteTypeAnnotation.ts, 78, 32))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>reg.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>reg.toString : Symbol(RegExp.toString, Decl(lib.es5.d.ts, --, --))
>reg : Symbol(reg, Decl(constructorWithIncompleteTypeAnnotation.ts, 81, 15))
>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
>toString : Symbol(RegExp.toString, Decl(lib.es5.d.ts, --, --))
>objLit : Symbol(objLit, Decl(constructorWithIncompleteTypeAnnotation.ts, 82, 15))
>weekday : Symbol(weekday, Decl(constructorWithIncompleteTypeAnnotation.ts, 83, 15))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
a1(...array2); // Error parameter type is (number|string)[]
~~~~~~
!!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
!!! related TS2728 /.ts/lib.es5.d.ts:1385:13: 'Array' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1392:13: 'Array' is declared here.
a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '[[any]]'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/destructuringTuple.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
!!! error TS2769: Types of property 'length' are incompatible.
!!! error TS2769: Type 'number' is not assignable to type '0'.
!!! related TS6502 /.ts/lib.es5.d.ts:1350:24: The expected type comes from the return type of this signature.
!!! related TS6502 /.ts/lib.es5.d.ts:1356:27: The expected type comes from the return type of this signature.
!!! related TS6502 /.ts/lib.es5.d.ts:1357:24: The expected type comes from the return type of this signature.
!!! related TS6502 /.ts/lib.es5.d.ts:1363:27: The expected type comes from the return type of this signature.
~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/externModule.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ tests/cases/compiler/externModule.ts(37,3): error TS2552: Cannot find name 'XDat
var d=new XDate();
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:909:13: 'Date' is declared here.
d.getDay();
d=new XDate(1978,2);
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:909:13: 'Date' is declared here.
d.getXDate();
var n=XDate.parse("3/2/2004");
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:909:13: 'Date' is declared here.
n=XDate.UTC(1964,2,1);
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:909:13: 'Date' is declared here.


2 changes: 1 addition & 1 deletion tests/baselines/reference/keyofAndIndexedAccess.types
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ...
>K02 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision"

type K03 = keyof boolean; // "valueOf"
>K03 : "valueOf"
>K03 : "toString" | "valueOf"

type K04 = keyof void; // never
>K04 : never
Expand Down

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions tests/baselines/reference/mappedTypeRecursiveInference.types

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.t
Math.sign(1);
~~~~
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
!!! related TS2728 /.ts/lib.es5.d.ts:713:5: 'sin' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:715:5: 'sin' is declared here.

// Using ES6 object
var o = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tests/cases/conformance/types/any/narrowExceptionVariableInCatchClause.ts(16,17)
err.massage; // ERROR: Property 'massage' does not exist on type 'Error'
~~~~~~~
!!! error TS2551: Property 'massage' does not exist on type 'Error'. Did you mean 'message'?
!!! related TS2728 /.ts/lib.es5.d.ts:974:5: 'message' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:979:5: 'message' is declared here.
}

else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ tests/cases/conformance/types/any/narrowFromAnyWithInstanceof.ts(22,7): error TS
x.mesage;
~~~~~~
!!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'?
!!! related TS2728 /.ts/lib.es5.d.ts:974:5: 'message' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:979:5: 'message' is declared here.
}

if (x instanceof Date) {
x.getDate();
x.getHuors();
~~~~~~~~
!!! error TS2551: Property 'getHuors' does not exist on type 'Date'. Did you mean 'getHours'?
!!! related TS2728 /.ts/lib.es5.d.ts:763:5: 'getHours' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:765:5: 'getHours' is declared here.
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ tests/cases/conformance/types/any/narrowFromAnyWithTypePredicate.ts(33,7): error
x.mesage;
~~~~~~
!!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'?
!!! related TS2728 /.ts/lib.es5.d.ts:974:5: 'message' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:979:5: 'message' is declared here.
}

if (isDate(x)) {
x.getDate();
x.getHuors();
~~~~~~~~
!!! error TS2551: Property 'getHuors' does not exist on type 'Date'. Did you mean 'getHours'?
!!! related TS2728 /.ts/lib.es5.d.ts:763:5: 'getHours' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:765:5: 'getHours' is declared here.
}

4 changes: 2 additions & 2 deletions tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.2_A1.5_T2.ts(20,3): error TS
$ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}

//CHECK#2
Expand All @@ -28,7 +28,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.2_A1.5_T2.ts(20,3): error TS
$ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}


Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.3_A1.1_T2.ts(17,3): error TS
$ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}


20 changes: 10 additions & 10 deletions tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,70 +50,70 @@ tests/cases/conformance/parser/ecmascript5/parserS7.6_A4.2_T1.ts(142,3): error T
$ERROR('#А');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0411 = 1;
if (Б !== 1) {
$ERROR('#Б');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0412 = 1;
if (В !== 1) {
$ERROR('#В');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0413 = 1;
if (Г !== 1) {
$ERROR('#Г');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0414 = 1;
if (Д !== 1) {
$ERROR('#Д');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0415 = 1;
if (Е !== 1) {
$ERROR('#Е');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0416 = 1;
if (Ж !== 1) {
$ERROR('#Ж');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0417 = 1;
if (З !== 1) {
$ERROR('#З');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0418 = 1;
if (И !== 1) {
$ERROR('#И');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u0419 = 1;
if (Й !== 1) {
$ERROR('#Й');
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
var \u041A = 1;
if (К !== 1) {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserUnicode1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ tests/cases/conformance/parser/ecmascript5/parserUnicode1.ts(10,5): error TS2552
$ERROR('#6.1: var \\u0078x = 1; xx === 6. Actual: ' + (xx));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}
}
catch (e) {
$ERROR('#6.2: var \\u0078x = 1; xx === 6. Actual: ' + (xx));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.

}
2 changes: 1 addition & 1 deletion tests/baselines/reference/promisePermutations.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2769: No overload m
!!! error TS2769: The last overload gave the following error.
!!! error TS2769: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
!!! error TS2769: Property 'catch' is missing in type 'IPromise<string>' but required in type 'Promise<number>'.
!!! related TS2728 /.ts/lib.es5.d.ts:1430:5: 'catch' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1437:5: 'catch' is declared here.
!!! related TS2771 tests/cases/compiler/promisePermutations.ts:5:5: The last overload is declared here.
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/promisePermutations2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
~~~~~~~~~
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
!!! error TS2345: Property 'catch' is missing in type 'IPromise<string>' but required in type 'Promise<number>'.
!!! related TS2728 /.ts/lib.es5.d.ts:1430:5: 'catch' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1437:5: 'catch' is declared here.
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok

var r11: IPromise<number>;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/promisePermutations3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
!!! error TS2769: The last overload gave the following error.
!!! error TS2769: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
!!! error TS2769: Property 'catch' is missing in type 'IPromise<string>' but required in type 'Promise<number>'.
!!! related TS2728 /.ts/lib.es5.d.ts:1430:5: 'catch' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1437:5: 'catch' is declared here.
!!! related TS2771 tests/cases/compiler/promisePermutations3.ts:7:5: The last overload is declared here.
var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok

Expand Down Expand Up @@ -445,5 +445,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ <T>(x: T): IPromise<T>; <T>(x: T, y: T): Promise<T>; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise<unknown>'.
!!! error TS2345: Property 'catch' is missing in type 'IPromise<any>' but required in type 'Promise<unknown>'.
!!! related TS2728 /.ts/lib.es5.d.ts:1430:5: 'catch' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1437:5: 'catch' is declared here.
var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok
2 changes: 1 addition & 1 deletion tests/baselines/reference/redefineArray.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ tests/cases/compiler/redefineArray.ts(1,1): error TS2741: Property 'isArray' is
Array = function (n:number, s:string) {return n;};
~~~~~
!!! error TS2741: Property 'isArray' is missing in type '(n: number, s: string) => number' but required in type 'ArrayConstructor'.
!!! related TS2728 /.ts/lib.es5.d.ts:1381:5: 'isArray' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1388:5: 'isArray' is declared here.
4 changes: 2 additions & 2 deletions tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.2_A1.5_T2.ts(20,3): error
$ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}

//CHECK#2
Expand All @@ -28,7 +28,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.2_A1.5_T2.ts(20,3): error
$ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}


Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.3_A1.1_T2.ts(17,3): error
$ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x));
~~~~~~
!!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'?
!!! related TS2728 /.ts/lib.es5.d.ts:984:13: 'Error' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:991:13: 'Error' is declared here.
}


Loading