-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fix #1809, introduce non primitive object type #12501
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ebe2fdb
Fix #1809, introduce non primitive type
HerringtonDarkholme db9dd38
enable parsing
HerringtonDarkholme ce4c95f
fix error reporting
HerringtonDarkholme b8648fa
add tests for non primitive type
HerringtonDarkholme 2fb51e7
address code review feedback
HerringtonDarkholme c19221c
accept new baselines
HerringtonDarkholme 186ce38
add tests for generic type argument under strict null checks
HerringtonDarkholme 8b411ef
address CR feedback
HerringtonDarkholme 66069fc
update implementation to use intrinsic type
HerringtonDarkholme 8993877
classify nonPrimitive type as narrowable rather than structured
HerringtonDarkholme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about
a = x
anda = y
? I think neither should have errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added