From 632619861df6d54c67caa8ac8b75cd4f84d3a3de Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Sat, 17 Sep 2016 11:14:11 +0900 Subject: [PATCH 1/4] change error message for assigning from object --- src/compiler/checker.ts | 6 ++- src/compiler/diagnosticMessages.json | 4 ++ ...ssigningFromObjecToAnythingElse.errors.txt | 38 +++++++++++++++++++ .../assigningFromObjecToAnythingElse.js | 18 +++++++++ .../reference/intTypeCheck.errors.txt | 36 ++++++++++++------ ...embersOfObjectAssignmentCompat2.errors.txt | 28 ++++++++------ ...mbersOfFunctionAssignmentCompat.errors.txt | 12 ++++-- ...mbersOfFunctionAssignmentCompat.errors.txt | 12 ++++-- ...serAutomaticSemicolonInsertion1.errors.txt | 12 ++++-- .../typeParametersShouldNotBeEqual.errors.txt | 2 + ...typeParametersShouldNotBeEqual2.errors.txt | 2 + ...typeParametersShouldNotBeEqual3.errors.txt | 4 ++ .../assigningFromObjecToAnythingElse.ts | 8 ++++ 13 files changed, 144 insertions(+), 38 deletions(-) create mode 100644 tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt create mode 100644 tests/baselines/reference/assigningFromObjecToAnythingElse.js create mode 100644 tests/cases/compiler/assigningFromObjecToAnythingElse.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5aae3beb415..a952f5a7c95 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19,7 +19,7 @@ namespace ts { export function getSymbolId(symbol: Symbol): number { if (!symbol.id) { - symbol.id = nextSymbolId; + symbol.id = nextSymbolId; nextSymbolId++; } @@ -6365,7 +6365,7 @@ namespace ts { } function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) { - const sourceType = typeToString(source); + const sourceType = typeToString(source); const targetType = typeToString(target); if ((globalStringType === source && stringType === target) || @@ -6501,6 +6501,8 @@ namespace ts { if (reportErrors) { if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) { tryElaborateErrorsForPrimitivesAndObjects(source, target); + } else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) { + reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0f3e90405a6..be4ee2fa07d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1959,6 +1959,10 @@ "category": "Error", "code": 2695 }, + "The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?": { + "category": "Error", + "code": 2696 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt b/tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt new file mode 100644 index 00000000000..2188474d9c9 --- /dev/null +++ b/tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/assigningFromObjecToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'exec' is missing in type 'Object'. +tests/cases/compiler/assigningFromObjecToAnythingElse.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'String'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'charAt' is missing in type 'Object'. +tests/cases/compiler/assigningFromObjecToAnythingElse.ts(6,5): error TS2322: Type 'Number' is not assignable to type 'String'. + Property 'charAt' is missing in type 'Number'. +tests/cases/compiler/assigningFromObjecToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'name' is missing in type 'Object'. + + +==== tests/cases/compiler/assigningFromObjecToAnythingElse.ts (4 errors) ==== + var x: Object; + var y: RegExp; + y = x; + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'RegExp'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'exec' is missing in type 'Object'. + + var a: String = Object.create(""); + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'String'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'charAt' is missing in type 'Object'. + var c: String = Object.create(1); + ~ +!!! error TS2322: Type 'Number' is not assignable to type 'String'. +!!! error TS2322: Property 'charAt' is missing in type 'Number'. + + var w: Error = new Object(); + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'Error'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'name' is missing in type 'Object'. + \ No newline at end of file diff --git a/tests/baselines/reference/assigningFromObjecToAnythingElse.js b/tests/baselines/reference/assigningFromObjecToAnythingElse.js new file mode 100644 index 00000000000..ec6dc0c789d --- /dev/null +++ b/tests/baselines/reference/assigningFromObjecToAnythingElse.js @@ -0,0 +1,18 @@ +//// [assigningFromObjecToAnythingElse.ts] +var x: Object; +var y: RegExp; +y = x; + +var a: String = Object.create(""); +var c: String = Object.create(1); + +var w: Error = new Object(); + + +//// [assigningFromObjecToAnythingElse.js] +var x; +var y; +y = x; +var a = Object.create(""); +var c = Object.create(1); +var w = new Object(); diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 2214c685956..f8b4fef7310 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -2,7 +2,8 @@ tests/cases/compiler/intTypeCheck.ts(35,6): error TS2304: Cannot find name 'p'. tests/cases/compiler/intTypeCheck.ts(71,6): error TS2304: Cannot find name 'p'. tests/cases/compiler/intTypeCheck.ts(85,5): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/intTypeCheck.ts(99,5): error TS2322: Type 'Object' is not assignable to type 'i1'. - Property 'p' is missing in type 'Object'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'p' is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(100,16): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(101,5): error TS2322: Type 'Base' is not assignable to type 'i1'. Property 'p' is missing in type 'Base'. @@ -15,7 +16,8 @@ tests/cases/compiler/intTypeCheck.ts(107,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(112,5): error TS2322: Type '{}' is not assignable to type 'i2'. Type '{}' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(113,5): error TS2322: Type 'Object' is not assignable to type 'i2'. - Type 'Object' provides no match for the signature '(): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(114,17): error TS2350: Only a void function can be called with the 'new' keyword. tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not assignable to type 'i2'. Type 'Base' provides no match for the signature '(): any' @@ -26,7 +28,8 @@ tests/cases/compiler/intTypeCheck.ts(121,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(126,5): error TS2322: Type '{}' is not assignable to type 'i3'. Type '{}' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(127,5): error TS2322: Type 'Object' is not assignable to type 'i3'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(129,5): error TS2322: Type 'Base' is not assignable to type 'i3'. Type 'Base' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is not assignable to type 'i3'. @@ -43,7 +46,8 @@ tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(154,5): error TS2322: Type '{}' is not assignable to type 'i5'. Property 'p' is missing in type '{}'. tests/cases/compiler/intTypeCheck.ts(155,5): error TS2322: Type 'Object' is not assignable to type 'i5'. - Property 'p' is missing in type 'Object'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'p' is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(156,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(157,5): error TS2322: Type 'Base' is not assignable to type 'i5'. Property 'p' is missing in type 'Base'. @@ -56,7 +60,8 @@ tests/cases/compiler/intTypeCheck.ts(163,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(168,5): error TS2322: Type '{}' is not assignable to type 'i6'. Type '{}' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(169,5): error TS2322: Type 'Object' is not assignable to type 'i6'. - Type 'Object' provides no match for the signature '(): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(170,17): error TS2350: Only a void function can be called with the 'new' keyword. tests/cases/compiler/intTypeCheck.ts(171,5): error TS2322: Type 'Base' is not assignable to type 'i6'. Type 'Base' provides no match for the signature '(): any' @@ -69,7 +74,8 @@ tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'. Type '{}' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(185,17): error TS2352: Type 'Base' cannot be converted to type 'i7'. Type 'Base' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'. @@ -193,7 +199,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj2: i1 = new Object(); ~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i1'. -!!! error TS2322: Property 'p' is missing in type 'Object'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'p' is missing in type 'Object'. var obj3: i1 = new obj0; ~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -229,7 +236,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj13: i2 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i2'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): any' var obj14: i2 = new obj11; ~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. @@ -262,7 +270,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj24: i3 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i3'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' var obj25: i3 = new obj22; var obj26: i3 = new Base; ~~~~~ @@ -320,7 +329,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj46: i5 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i5'. -!!! error TS2322: Property 'p' is missing in type 'Object'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'p' is missing in type 'Object'. var obj47: i5 = new obj44; ~~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -356,7 +366,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj57: i6 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i6'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): any' var obj58: i6 = new obj55; ~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. @@ -392,7 +403,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj68: i7 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i7'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' var obj69: i7 = new obj66; var obj70: i7 = new Base; ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt b/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt index a88796b390e..3e27b22240e 100644 --- a/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt +++ b/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt @@ -3,17 +3,19 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC Type '() => number' is not assignable to type '() => string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Types of property 'toString' are incompatible. - Type '() => string' is not assignable to type '() => number'. - Type 'string' is not assignable to type 'number'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Types of property 'toString' are incompatible. + Type '() => string' is not assignable to type '() => number'. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(14,1): error TS2322: Type 'C' is not assignable to type 'Object'. Types of property 'toString' are incompatible. Type '() => number' is not assignable to type '() => string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(15,1): error TS2322: Type 'Object' is not assignable to type 'C'. - Types of property 'toString' are incompatible. - Type '() => string' is not assignable to type '() => number'. - Type 'string' is not assignable to type 'number'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Types of property 'toString' are incompatible. + Type '() => string' is not assignable to type '() => number'. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(20,1): error TS2322: Type '{ toString: () => void; }' is not assignable to type 'Object'. Types of property 'toString' are incompatible. Type '() => void' is not assignable to type '() => string'. @@ -36,9 +38,10 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC i = o; // error ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Types of property 'toString' are incompatible. -!!! error TS2322: Type '() => string' is not assignable to type '() => number'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Types of property 'toString' are incompatible. +!!! error TS2322: Type '() => string' is not assignable to type '() => number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. class C { toString(): number { return 1; } @@ -53,9 +56,10 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC c = o; // error ~ !!! error TS2322: Type 'Object' is not assignable to type 'C'. -!!! error TS2322: Types of property 'toString' are incompatible. -!!! error TS2322: Type '() => string' is not assignable to type '() => number'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Types of property 'toString' are incompatible. +!!! error TS2322: Type '() => string' is not assignable to type '() => number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. var a = { toString: () => { } diff --git a/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt b/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt index e296f2113fb..caeca11edf8 100644 --- a/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt +++ b/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts(14,1): error TS2322: Type 'Object' is not assignable to type '() => void'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' ==== tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts (2 errors) ==== @@ -15,7 +17,8 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOf i = f; ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' var a: { (): void @@ -24,4 +27,5 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOf a = f; ~ !!! error TS2322: Type 'Object' is not assignable to type '() => void'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' \ No newline at end of file +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' \ No newline at end of file diff --git a/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt b/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt index 227ccc99603..ad0e801e435 100644 --- a/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt +++ b/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts(14,1): error TS2322: Type 'Object' is not assignable to type 'new () => any'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' ==== tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts (2 errors) ==== @@ -15,7 +17,8 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMemb i = f; ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' var a: { new(): any @@ -24,4 +27,5 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMemb a = f; ~ !!! error TS2322: Type 'Object' is not assignable to type 'new () => any'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' \ No newline at end of file +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' \ No newline at end of file diff --git a/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt b/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt index 9ffdc614ab1..a2bbb98fbf4 100644 --- a/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt +++ b/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts(14,1): error TS2322: Type 'Object' is not assignable to type '() => void'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' ==== tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts (2 errors) ==== @@ -15,7 +17,8 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAut i = o; ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' var a: { (): void @@ -24,5 +27,6 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAut a = o; ~ !!! error TS2322: Type 'Object' is not assignable to type '() => void'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' \ No newline at end of file diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt index 6f5e2766c8c..b5c9fd60206 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/typeParametersShouldNotBeEqual.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/compiler/typeParametersShouldNotBeEqual.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? ==== tests/cases/compiler/typeParametersShouldNotBeEqual.ts (2 errors) ==== @@ -12,6 +13,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual.ts(5,5): error TS2322: Type x = z; // Error ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? z = x; // Ok } \ No newline at end of file diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt index 27ac1e07eab..d452b997980 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt @@ -7,6 +7,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(7,5): error TS2322: Type tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(8,5): error TS2322: Type 'U' is not assignable to type 'V'. Type 'Date' is not assignable to type 'V'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? ==== tests/cases/compiler/typeParametersShouldNotBeEqual2.ts (6 errors) ==== @@ -34,6 +35,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type x = zz; // Error ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? zz = x; // Ok } \ No newline at end of file diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt index 0169f57c06f..816db440a4c 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt @@ -1,6 +1,8 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'. Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? ==== tests/cases/compiler/typeParametersShouldNotBeEqual3.ts (2 errors) ==== @@ -11,9 +13,11 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? x = z; // Ok ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? z = x; // Ok } \ No newline at end of file diff --git a/tests/cases/compiler/assigningFromObjecToAnythingElse.ts b/tests/cases/compiler/assigningFromObjecToAnythingElse.ts new file mode 100644 index 00000000000..ebf1a0a8763 --- /dev/null +++ b/tests/cases/compiler/assigningFromObjecToAnythingElse.ts @@ -0,0 +1,8 @@ +var x: Object; +var y: RegExp; +y = x; + +var a: String = Object.create(""); +var c: String = Object.create(1); + +var w: Error = new Object(); From c76b8b165b37177297f76c29e509f896d8d4db5e Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Sat, 17 Sep 2016 21:45:46 +0900 Subject: [PATCH 2/4] fix linting error --- src/compiler/checker.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a952f5a7c95..7f45e4091b7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19,7 +19,7 @@ namespace ts { export function getSymbolId(symbol: Symbol): number { if (!symbol.id) { - symbol.id = nextSymbolId; + symbol.id = nextSymbolId; nextSymbolId++; } @@ -6365,7 +6365,7 @@ namespace ts { } function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) { - const sourceType = typeToString(source); + const sourceType = typeToString(source); const targetType = typeToString(target); if ((globalStringType === source && stringType === target) || @@ -6501,7 +6501,8 @@ namespace ts { if (reportErrors) { if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) { tryElaborateErrorsForPrimitivesAndObjects(source, target); - } else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) { + } + else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) { reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); From bf471c221be1f44c58dc77419869639bfd4fc8ea Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Wed, 21 Sep 2016 06:44:09 +0900 Subject: [PATCH 3/4] fix typo --- ...signingFromObjectToAnythingElse.errors.txt | 38 +++++++++++++++++++ .../assigningFromObjectToAnythingElse.js | 18 +++++++++ ...s => assigningFromObjectToAnythingElse.ts} | 0 3 files changed, 56 insertions(+) create mode 100644 tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt create mode 100644 tests/baselines/reference/assigningFromObjectToAnythingElse.js rename tests/cases/compiler/{assigningFromObjecToAnythingElse.ts => assigningFromObjectToAnythingElse.ts} (100%) diff --git a/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt new file mode 100644 index 00000000000..289883d7471 --- /dev/null +++ b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'exec' is missing in type 'Object'. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'String'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'charAt' is missing in type 'Object'. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,5): error TS2322: Type 'Number' is not assignable to type 'String'. + Property 'charAt' is missing in type 'Number'. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'name' is missing in type 'Object'. + + +==== tests/cases/compiler/assigningFromObjectToAnythingElse.ts (4 errors) ==== + var x: Object; + var y: RegExp; + y = x; + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'RegExp'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'exec' is missing in type 'Object'. + + var a: String = Object.create(""); + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'String'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'charAt' is missing in type 'Object'. + var c: String = Object.create(1); + ~ +!!! error TS2322: Type 'Number' is not assignable to type 'String'. +!!! error TS2322: Property 'charAt' is missing in type 'Number'. + + var w: Error = new Object(); + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'Error'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'name' is missing in type 'Object'. + \ No newline at end of file diff --git a/tests/baselines/reference/assigningFromObjectToAnythingElse.js b/tests/baselines/reference/assigningFromObjectToAnythingElse.js new file mode 100644 index 00000000000..61c4a6ede22 --- /dev/null +++ b/tests/baselines/reference/assigningFromObjectToAnythingElse.js @@ -0,0 +1,18 @@ +//// [assigningFromObjectToAnythingElse.ts] +var x: Object; +var y: RegExp; +y = x; + +var a: String = Object.create(""); +var c: String = Object.create(1); + +var w: Error = new Object(); + + +//// [assigningFromObjectToAnythingElse.js] +var x; +var y; +y = x; +var a = Object.create(""); +var c = Object.create(1); +var w = new Object(); diff --git a/tests/cases/compiler/assigningFromObjecToAnythingElse.ts b/tests/cases/compiler/assigningFromObjectToAnythingElse.ts similarity index 100% rename from tests/cases/compiler/assigningFromObjecToAnythingElse.ts rename to tests/cases/compiler/assigningFromObjectToAnythingElse.ts From c1aff4f0d7d2a68b7446144d96e1e6734a7b3988 Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Thu, 22 Sep 2016 00:06:11 +0900 Subject: [PATCH 4/4] remove extra files --- ...ssigningFromObjecToAnythingElse.errors.txt | 38 ------------------- .../assigningFromObjecToAnythingElse.js | 18 --------- 2 files changed, 56 deletions(-) delete mode 100644 tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt delete mode 100644 tests/baselines/reference/assigningFromObjecToAnythingElse.js diff --git a/tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt b/tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt deleted file mode 100644 index 2188474d9c9..00000000000 --- a/tests/baselines/reference/assigningFromObjecToAnythingElse.errors.txt +++ /dev/null @@ -1,38 +0,0 @@ -tests/cases/compiler/assigningFromObjecToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'. - The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? - Property 'exec' is missing in type 'Object'. -tests/cases/compiler/assigningFromObjecToAnythingElse.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'String'. - The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? - Property 'charAt' is missing in type 'Object'. -tests/cases/compiler/assigningFromObjecToAnythingElse.ts(6,5): error TS2322: Type 'Number' is not assignable to type 'String'. - Property 'charAt' is missing in type 'Number'. -tests/cases/compiler/assigningFromObjecToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'. - The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? - Property 'name' is missing in type 'Object'. - - -==== tests/cases/compiler/assigningFromObjecToAnythingElse.ts (4 errors) ==== - var x: Object; - var y: RegExp; - y = x; - ~ -!!! error TS2322: Type 'Object' is not assignable to type 'RegExp'. -!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? -!!! error TS2322: Property 'exec' is missing in type 'Object'. - - var a: String = Object.create(""); - ~ -!!! error TS2322: Type 'Object' is not assignable to type 'String'. -!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? -!!! error TS2322: Property 'charAt' is missing in type 'Object'. - var c: String = Object.create(1); - ~ -!!! error TS2322: Type 'Number' is not assignable to type 'String'. -!!! error TS2322: Property 'charAt' is missing in type 'Number'. - - var w: Error = new Object(); - ~ -!!! error TS2322: Type 'Object' is not assignable to type 'Error'. -!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? -!!! error TS2322: Property 'name' is missing in type 'Object'. - \ No newline at end of file diff --git a/tests/baselines/reference/assigningFromObjecToAnythingElse.js b/tests/baselines/reference/assigningFromObjecToAnythingElse.js deleted file mode 100644 index ec6dc0c789d..00000000000 --- a/tests/baselines/reference/assigningFromObjecToAnythingElse.js +++ /dev/null @@ -1,18 +0,0 @@ -//// [assigningFromObjecToAnythingElse.ts] -var x: Object; -var y: RegExp; -y = x; - -var a: String = Object.create(""); -var c: String = Object.create(1); - -var w: Error = new Object(); - - -//// [assigningFromObjecToAnythingElse.js] -var x; -var y; -y = x; -var a = Object.create(""); -var c = Object.create(1); -var w = new Object();