Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"Decorators are not valid here.": 1206,
"'abstract' modifier can only appear on a class, method, or property declaration.": 1242,
"Method '{0}' cannot have an implementation because it is marked abstract.": 1245,
"An interface property cannot have an initializer.": 1246,
"A definite assignment assertion '!' is not permitted in this context.": 1255,
"A class may only extend another class.": 1311,
"A parameter property cannot be declared using a rest parameter.": 1317,
Expand Down
4 changes: 4 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,10 @@ export class Program extends DiagnosticEmitter {
/** Parent interface. */
parent: InterfacePrototype
): void {
let initializer = declaration.initializer;
if (initializer) {
this.error(DiagnosticCode.An_interface_property_cannot_have_an_initializer, initializer.range);
}
let typeNode = declaration.type;
if (!typeNode) typeNode = Node.createOmittedType(declaration.name.range.atEnd);
this.initializeProperty(
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/interface-with-initializer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"asc_flags": [
],
"stderr": [
"TS1246: An interface property cannot have an initializer."
]
}
9 changes: 9 additions & 0 deletions tests/compiler/interface-with-initializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface I {
v: string = "";
}

class C implements I {
v: string = "";
}

new C();