-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Give more helpful error when trying to set default values on an interface. #5736
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c93f454
Implement #5173
delta-nry 40a2a25
Fix object type literal regression
delta-nry 5b3d299
Clarify comment
delta-nry 068d10c
Add tests for #5173
delta-nry 6c755c9
Report property errors in the checker instead of the parser
delta-nry d9d67d9
Move initializer checks into checkGrammarProperty
delta-nry e363c75
Revert baseline changes to the objectTypeLiteralSyntax2 test
delta-nry 144d24c
Change "object type literal" to "type literal"
delta-nry 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2247,6 +2247,14 @@ namespace ts { | |
| property.name = name; | ||
| property.questionToken = questionToken; | ||
| property.type = parseTypeAnnotation(); | ||
|
|
||
| if (token === SyntaxKind.EqualsToken) { | ||
| // Although object type properties cannot not have initializers, we attempt | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type literal properties |
||
| // to parse an initializer so we can report in the checker that an interface | ||
| // property or object type literal property cannot have an initializer. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type literal |
||
| property.initializer = parseNonParameterInitializer(); | ||
| } | ||
|
|
||
| parseTypeMemberSemicolon(); | ||
| return finishNode(property); | ||
| } | ||
|
|
||
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
tests/baselines/reference/errorOnInitializerInInterfaceProperty.errors.txt
This file contains hidden or 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/compiler/errorOnInitializerInInterfaceProperty.ts(2,19): error TS1246: An interface property cannot have an initializer. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/errorOnInitializerInInterfaceProperty.ts (1 errors) ==== | ||
| interface Foo { | ||
| bar: number = 5; | ||
| ~ | ||
| !!! error TS1246: An interface property cannot have an initializer. | ||
| } | ||
|
|
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/errorOnInitializerInInterfaceProperty.js
This file contains hidden or 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,7 @@ | ||
| //// [errorOnInitializerInInterfaceProperty.ts] | ||
| interface Foo { | ||
| bar: number = 5; | ||
| } | ||
|
|
||
|
|
||
| //// [errorOnInitializerInInterfaceProperty.js] |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/errorOnInitializerInObjectTypeLiteralProperty.errors.txt
This file contains hidden or 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,17 @@ | ||
| tests/cases/compiler/errorOnInitializerInObjectTypeLiteralProperty.ts(2,19): error TS1247: An object type literal property cannot have an initializer. | ||
| tests/cases/compiler/errorOnInitializerInObjectTypeLiteralProperty.ts(6,19): error TS1247: An object type literal property cannot have an initializer. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/errorOnInitializerInObjectTypeLiteralProperty.ts (2 errors) ==== | ||
| var Foo: { | ||
| bar: number = 5; | ||
| ~ | ||
| !!! error TS1247: An object type literal property cannot have an initializer. | ||
| }; | ||
|
|
||
| let Bar: { | ||
| bar: number = 5; | ||
| ~ | ||
| !!! error TS1247: An object type literal property cannot have an initializer. | ||
| }; | ||
|
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/errorOnInitializerInObjectTypeLiteralProperty.js
This file contains hidden or 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 @@ | ||
| //// [errorOnInitializerInObjectTypeLiteralProperty.ts] | ||
| var Foo: { | ||
| bar: number = 5; | ||
| }; | ||
|
|
||
| let Bar: { | ||
| bar: number = 5; | ||
| }; | ||
|
|
||
|
|
||
| //// [errorOnInitializerInObjectTypeLiteralProperty.js] | ||
| var Foo; | ||
| var Bar; |
3 changes: 3 additions & 0 deletions
3
tests/cases/compiler/errorOnInitializerInInterfaceProperty.ts
This file contains hidden or 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,3 @@ | ||
| interface Foo { | ||
| bar: number = 5; | ||
| } |
7 changes: 7 additions & 0 deletions
7
tests/cases/compiler/errorOnInitializerInObjectTypeLiteralProperty.ts
This file contains hidden or 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,7 @@ | ||
| var Foo: { | ||
| bar: number = 5; | ||
| }; | ||
|
|
||
| let Bar: { | ||
| bar: number = 5; | ||
| }; |
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.
Sorry I didn't notice it earlier, but this should be "A type literal property"