mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Merge pull request #2263 from DickvdBrink/valueOf-lib.d.ts
Added valueOf definitions for String and Number
This commit is contained in:
commit
161d6463ab
6
src/lib/core.d.ts
vendored
6
src/lib/core.d.ts
vendored
@ -410,6 +410,9 @@ interface String {
|
||||
*/
|
||||
substr(from: number, length?: number): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): string;
|
||||
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
@ -462,6 +465,9 @@ interface Number {
|
||||
* @param precision Number of significant digits. Must be in the range 1 - 21, inclusive.
|
||||
*/
|
||||
toPrecision(precision?: number): string;
|
||||
|
||||
/** Returns the primitive value of the specified object. */
|
||||
valueOf(): number;
|
||||
}
|
||||
|
||||
interface NumberConstructor {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/types/primitives/number/assignFromNumberInterface2.ts(23,1): error TS2322: Type 'Number' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/primitives/number/assignFromNumberInterface2.ts(24,1): error TS2322: Type 'NotNumber' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/primitives/number/assignFromNumberInterface2.ts(24,1): error TS2322: Type 'Number' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/primitives/number/assignFromNumberInterface2.ts(25,1): error TS2322: Type 'NotNumber' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/primitives/number/assignFromNumberInterface2.ts (2 errors) ====
|
||||
@ -12,6 +12,7 @@ tests/cases/conformance/types/primitives/number/assignFromNumberInterface2.ts(24
|
||||
toFixed(fractionDigits?: number): string;
|
||||
toExponential(fractionDigits?: number): string;
|
||||
toPrecision(precision?: number): string;
|
||||
valueOf(): number;
|
||||
doStuff(): string;
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ interface NotNumber {
|
||||
toFixed(fractionDigits?: number): string;
|
||||
toExponential(fractionDigits?: number): string;
|
||||
toPrecision(precision?: number): string;
|
||||
valueOf(): number;
|
||||
doStuff(): string;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(46,1): error TS2322: Type 'String' is not assignable to type 'string'.
|
||||
tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(47,1): error TS2322: Type 'NotString' is not assignable to type 'string'.
|
||||
tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(47,1): error TS2322: Type 'String' is not assignable to type 'string'.
|
||||
tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(48,1): error TS2322: Type 'NotString' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts (2 errors) ====
|
||||
@ -35,6 +35,7 @@ tests/cases/conformance/types/primitives/string/assignFromStringInterface2.ts(47
|
||||
trim(): string;
|
||||
length: number;
|
||||
substr(from: number, length?: number): string;
|
||||
valueOf(): string;
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ interface NotString {
|
||||
trim(): string;
|
||||
length: number;
|
||||
substr(from: number, length?: number): string;
|
||||
valueOf(): string;
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
tests/cases/compiler/booleanAssignment.ts(2,1): error TS2322: Type 'number' is not assignable to type 'Boolean'.
|
||||
Types of property 'valueOf' are incompatible.
|
||||
Type '() => Object' is not assignable to type '() => boolean'.
|
||||
Type 'Object' is not assignable to type 'boolean'.
|
||||
Type '() => number' is not assignable to type '() => boolean'.
|
||||
Type 'number' is not assignable to type 'boolean'.
|
||||
tests/cases/compiler/booleanAssignment.ts(3,1): error TS2322: Type 'string' is not assignable to type 'Boolean'.
|
||||
Types of property 'valueOf' are incompatible.
|
||||
Type '() => Object' is not assignable to type '() => boolean'.
|
||||
Type '() => string' is not assignable to type '() => boolean'.
|
||||
Type 'string' is not assignable to type 'boolean'.
|
||||
tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not assignable to type 'Boolean'.
|
||||
Types of property 'valueOf' are incompatible.
|
||||
Type '() => Object' is not assignable to type '() => boolean'.
|
||||
Type 'Object' is not assignable to type 'boolean'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/booleanAssignment.ts (3 errors) ====
|
||||
@ -16,18 +18,20 @@ tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not a
|
||||
~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'Boolean'.
|
||||
!!! error TS2322: Types of property 'valueOf' are incompatible.
|
||||
!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'.
|
||||
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type '() => number' is not assignable to type '() => boolean'.
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.
|
||||
b = "a"; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'Boolean'.
|
||||
!!! error TS2322: Types of property 'valueOf' are incompatible.
|
||||
!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'.
|
||||
!!! error TS2322: Type '() => string' is not assignable to type '() => boolean'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
|
||||
b = {}; // Error
|
||||
~
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'Boolean'.
|
||||
!!! error TS2322: Types of property 'valueOf' are incompatible.
|
||||
!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'.
|
||||
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
|
||||
|
||||
var o = {};
|
||||
o = b; // OK
|
||||
|
||||
@ -3,14 +3,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLite
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(30,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(34,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(38,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(76,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(89,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(93,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(77,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(90,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(94,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(95,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(97,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(96,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(98,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(99,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(100,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts (13 errors) ====
|
||||
@ -86,6 +86,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLite
|
||||
trim(): string { return null; }
|
||||
length: number;
|
||||
substr(from: number, length?: number): string { return null; }
|
||||
valueOf(): string { return null; }
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,7 @@ class C implements String {
|
||||
trim(): string { return null; }
|
||||
length: number;
|
||||
substr(from: number, length?: number): string { return null; }
|
||||
valueOf(): string { return null; }
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
@ -138,6 +139,7 @@ var C = (function () {
|
||||
C.prototype.toLocaleUpperCase = function () { return null; };
|
||||
C.prototype.trim = function () { return null; };
|
||||
C.prototype.substr = function (from, length) { return null; };
|
||||
C.prototype.valueOf = function () { return null; };
|
||||
return C;
|
||||
})();
|
||||
function f10(x) { }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'.
|
||||
lib.d.ts(521,11): error TS2300: Duplicate identifier 'TemplateStringsArray'.
|
||||
tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'.
|
||||
tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'.
|
||||
Property 'raw' is missing in type '{ [x: number]: undefined; }'.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'.
|
||||
lib.d.ts(521,11): error TS2300: Duplicate identifier 'TemplateStringsArray'.
|
||||
tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'.
|
||||
tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'.
|
||||
Property 'raw' is missing in type '{ [x: number]: undefined; }'.
|
||||
|
||||
@ -7,6 +7,7 @@ interface NotNumber {
|
||||
toFixed(fractionDigits?: number): string;
|
||||
toExponential(fractionDigits?: number): string;
|
||||
toPrecision(precision?: number): string;
|
||||
valueOf(): number;
|
||||
doStuff(): string;
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ interface NotString {
|
||||
trim(): string;
|
||||
length: number;
|
||||
substr(from: number, length?: number): string;
|
||||
valueOf(): string;
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,7 @@ class C implements String {
|
||||
trim(): string { return null; }
|
||||
length: number;
|
||||
substr(from: number, length?: number): string { return null; }
|
||||
valueOf(): string { return null; }
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
|
||||
@ -16,4 +16,5 @@
|
||||
|
||||
goTo.marker();
|
||||
verify.memberListContains("toString", "(method) toString(): string");
|
||||
verify.memberListCount(1);
|
||||
verify.memberListContains("valueOf", "(method) valueOf(): string | number");
|
||||
verify.memberListCount(2);
|
||||
@ -21,4 +21,4 @@ verify.memberListCount(0);
|
||||
goTo.marker('enumValueReference');
|
||||
verify.memberListContains("toString");
|
||||
verify.memberListContains("toFixed");
|
||||
verify.memberListCount(4);
|
||||
verify.memberListCount(5);
|
||||
|
||||
@ -7,11 +7,10 @@
|
||||
goTo.marker('1');
|
||||
edit.insert('.');
|
||||
verify.memberListContains('trim');
|
||||
verify.memberListCount(20);
|
||||
verify.memberListCount(21);
|
||||
edit.insert('});'); // need the following lines to not have parse errors in order for completion list to appear
|
||||
|
||||
goTo.marker('2');
|
||||
edit.insert('.');
|
||||
verify.memberListContains('trim');
|
||||
verify.memberListCount(20);
|
||||
|
||||
verify.memberListCount(21);
|
||||
|
||||
@ -7,11 +7,10 @@
|
||||
goTo.marker('1');
|
||||
edit.insert('.');
|
||||
verify.memberListContains('trim');
|
||||
verify.memberListCount(20);
|
||||
verify.memberListCount(21);
|
||||
edit.insert('});'); // need the following lines to not have parse errors in order for completion list to appear
|
||||
|
||||
goTo.marker('2');
|
||||
edit.insert('.');
|
||||
verify.memberListContains('trim');
|
||||
verify.memberListCount(20);
|
||||
|
||||
verify.memberListCount(21);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user