-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Changes from 6 commits
c93f454
40a2a25
5b3d299
068d10c
6c755c9
d9d67d9
e363c75
144d24c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//// [errorOnInitializerInInterfaceProperty.ts] | ||
interface Foo { | ||
bar: number = 5; | ||
} | ||
|
||
|
||
//// [errorOnInitializerInInterfaceProperty.js] |
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. | ||
}; | ||
|
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS1005: ';' expected. | ||
tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS1005: '=' expected. | ||
tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,22): error TS2304: Cannot find name 'bar'. | ||
tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,25): error TS1005: ';' expected. | ||
|
||
|
||
==== tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts (1 errors) ==== | ||
==== tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts (3 errors) ==== | ||
var x: { | ||
foo: string, | ||
bar: string | ||
|
@@ -15,4 +17,8 @@ tests/cases/conformance/types/objectTypeLiteral/objectTypeLiteralSyntax2.ts(12,2 | |
|
||
var z: { foo: string bar: string } | ||
~~~ | ||
!!! error TS1005: '=' expected. | ||
~~~ | ||
!!! error TS2304: Cannot find name 'bar'. | ||
~ | ||
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. I'm not sure if we should accept these errors, as the 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. It should be sufficient if you make it so that you only try to parse an initializer if the current token is a |
||
!!! error TS1005: ';' expected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface Foo { | ||
bar: number = 5; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var Foo: { | ||
bar: number = 5; | ||
}; | ||
|
||
let Bar: { | ||
bar: number = 5; | ||
}; |
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"