-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12501 from HerringtonDarkholme/non-primitive
Fix #1809, introduce non primitive object type
- Loading branch information
Showing
36 changed files
with
978 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//// [assignObjectToNonPrimitive.ts] | ||
var x = {}; | ||
var y = {foo: "bar"}; | ||
var a: object; | ||
a = x; | ||
a = y; | ||
|
||
|
||
//// [assignObjectToNonPrimitive.js] | ||
var x = {}; | ||
var y = { foo: "bar" }; | ||
var a; | ||
a = x; | ||
a = y; |
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/assignObjectToNonPrimitive.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
=== tests/cases/conformance/types/nonPrimitive/assignObjectToNonPrimitive.ts === | ||
var x = {}; | ||
>x : Symbol(x, Decl(assignObjectToNonPrimitive.ts, 0, 3)) | ||
|
||
var y = {foo: "bar"}; | ||
>y : Symbol(y, Decl(assignObjectToNonPrimitive.ts, 1, 3)) | ||
>foo : Symbol(foo, Decl(assignObjectToNonPrimitive.ts, 1, 9)) | ||
|
||
var a: object; | ||
>a : Symbol(a, Decl(assignObjectToNonPrimitive.ts, 2, 3)) | ||
|
||
a = x; | ||
>a : Symbol(a, Decl(assignObjectToNonPrimitive.ts, 2, 3)) | ||
>x : Symbol(x, Decl(assignObjectToNonPrimitive.ts, 0, 3)) | ||
|
||
a = y; | ||
>a : Symbol(a, Decl(assignObjectToNonPrimitive.ts, 2, 3)) | ||
>y : Symbol(y, Decl(assignObjectToNonPrimitive.ts, 1, 3)) | ||
|
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/assignObjectToNonPrimitive.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
=== tests/cases/conformance/types/nonPrimitive/assignObjectToNonPrimitive.ts === | ||
var x = {}; | ||
>x : {} | ||
>{} : {} | ||
|
||
var y = {foo: "bar"}; | ||
>y : { foo: string; } | ||
>{foo: "bar"} : { foo: string; } | ||
>foo : string | ||
>"bar" : "bar" | ||
|
||
var a: object; | ||
>a : object | ||
|
||
a = x; | ||
>a = x : {} | ||
>a : object | ||
>x : {} | ||
|
||
a = y; | ||
>a = y : { foo: string; } | ||
>a : object | ||
>y : { foo: string; } | ||
|
10 changes: 10 additions & 0 deletions
10
tests/baselines/reference/nonPrimitiveAccessProperty.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts(3,3): error TS2339: Property 'nonExist' does not exist on type 'object'. | ||
|
||
|
||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts (1 errors) ==== | ||
var a: object; | ||
a.toString(); | ||
a.nonExist(); // error | ||
~~~~~~~~ | ||
!!! error TS2339: Property 'nonExist' does not exist on type 'object'. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//// [nonPrimitiveAccessProperty.ts] | ||
var a: object; | ||
a.toString(); | ||
a.nonExist(); // error | ||
|
||
|
||
//// [nonPrimitiveAccessProperty.js] | ||
var a; | ||
a.toString(); | ||
a.nonExist(); // error |
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/nonPrimitiveAsProperty.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAsProperty.ts(7,5): error TS2322: Type '{ foo: string; }' is not assignable to type 'WithNonPrimitive'. | ||
Types of property 'foo' are incompatible. | ||
Type 'string' is not assignable to type 'object'. | ||
|
||
|
||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAsProperty.ts (1 errors) ==== | ||
interface WithNonPrimitive { | ||
foo: object | ||
} | ||
|
||
var a: WithNonPrimitive = { foo: {bar: "bar"} }; | ||
|
||
var b: WithNonPrimitive = {foo: "bar"}; // expect error | ||
~ | ||
!!! error TS2322: Type '{ foo: string; }' is not assignable to type 'WithNonPrimitive'. | ||
!!! error TS2322: Types of property 'foo' are incompatible. | ||
!!! error TS2322: Type 'string' is not assignable to type 'object'. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [nonPrimitiveAsProperty.ts] | ||
interface WithNonPrimitive { | ||
foo: object | ||
} | ||
|
||
var a: WithNonPrimitive = { foo: {bar: "bar"} }; | ||
|
||
var b: WithNonPrimitive = {foo: "bar"}; // expect error | ||
|
||
|
||
//// [nonPrimitiveAsProperty.js] | ||
var a = { foo: { bar: "bar" } }; | ||
var b = { foo: "bar" }; // expect error |
54 changes: 54 additions & 0 deletions
54
tests/baselines/reference/nonPrimitiveAssignError.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(5,1): error TS2322: Type 'object' is not assignable to type '{ foo: string; }'. | ||
Property 'foo' is missing in type 'Object'. | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(13,1): error TS2322: Type 'number' is not assignable to type 'object'. | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(14,1): error TS2322: Type 'true' is not assignable to type 'object'. | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(15,1): error TS2322: Type 'string' is not assignable to type 'object'. | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(17,1): error TS2322: Type 'object' is not assignable to type 'number'. | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(18,1): error TS2322: Type 'object' is not assignable to type 'boolean'. | ||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(19,1): error TS2322: Type 'object' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts (7 errors) ==== | ||
var x = {}; | ||
var y = {foo: "bar"}; | ||
var a: object; | ||
x = a; | ||
y = a; // expect error | ||
~ | ||
!!! error TS2322: Type 'object' is not assignable to type '{ foo: string; }'. | ||
!!! error TS2322: Property 'foo' is missing in type 'Object'. | ||
a = x; | ||
a = y; | ||
|
||
var n = 123; | ||
var b = true; | ||
var s = "fooo"; | ||
|
||
a = n; // expect error | ||
~ | ||
!!! error TS2322: Type 'number' is not assignable to type 'object'. | ||
a = b; // expect error | ||
~ | ||
!!! error TS2322: Type 'true' is not assignable to type 'object'. | ||
a = s; // expect error | ||
~ | ||
!!! error TS2322: Type 'string' is not assignable to type 'object'. | ||
|
||
n = a; // expect error | ||
~ | ||
!!! error TS2322: Type 'object' is not assignable to type 'number'. | ||
b = a; // expect error | ||
~ | ||
!!! error TS2322: Type 'object' is not assignable to type 'boolean'. | ||
s = a; // expect error | ||
~ | ||
!!! error TS2322: Type 'object' is not assignable to type 'string'. | ||
|
||
var numObj: Number = 123; | ||
var boolObj: Boolean = true; | ||
var strObj: String = "string"; | ||
|
||
a = numObj; // ok | ||
a = boolObj; // ok | ||
a = strObj; // ok | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//// [nonPrimitiveAssignError.ts] | ||
var x = {}; | ||
var y = {foo: "bar"}; | ||
var a: object; | ||
x = a; | ||
y = a; // expect error | ||
a = x; | ||
a = y; | ||
|
||
var n = 123; | ||
var b = true; | ||
var s = "fooo"; | ||
|
||
a = n; // expect error | ||
a = b; // expect error | ||
a = s; // expect error | ||
|
||
n = a; // expect error | ||
b = a; // expect error | ||
s = a; // expect error | ||
|
||
var numObj: Number = 123; | ||
var boolObj: Boolean = true; | ||
var strObj: String = "string"; | ||
|
||
a = numObj; // ok | ||
a = boolObj; // ok | ||
a = strObj; // ok | ||
|
||
|
||
//// [nonPrimitiveAssignError.js] | ||
var x = {}; | ||
var y = { foo: "bar" }; | ||
var a; | ||
x = a; | ||
y = a; // expect error | ||
a = x; | ||
a = y; | ||
var n = 123; | ||
var b = true; | ||
var s = "fooo"; | ||
a = n; // expect error | ||
a = b; // expect error | ||
a = s; // expect error | ||
n = a; // expect error | ||
b = a; // expect error | ||
s = a; // expect error | ||
var numObj = 123; | ||
var boolObj = true; | ||
var strObj = "string"; | ||
a = numObj; // ok | ||
a = boolObj; // ok | ||
a = strObj; // ok |
Oops, something went wrong.