Skip to content

Commit 75ca641

Browse files
Fix error on interfaces in .js files (#35969)
* Use the correct error message. * Accepted baselines.
1 parent 82b0547 commit 75ca641

File tree

4 files changed

+59
-57
lines changed

4 files changed

+59
-57
lines changed

src/compiler/program.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,9 @@ namespace ts {
18371837
}
18381838
break;
18391839
case SyntaxKind.InterfaceDeclaration:
1840-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Interface_declaration_cannot_have_implements_clause));
1840+
const interfaceKeyword = tokenToString(SyntaxKind.InterfaceKeyword);
1841+
Debug.assertDefined(interfaceKeyword);
1842+
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, interfaceKeyword));
18411843
return;
18421844
case SyntaxKind.ModuleDeclaration:
18431845
const moduleKeyword = node.flags & NodeFlags.Namespace ? tokenToString(SyntaxKind.NamespaceKeyword) : tokenToString(SyntaxKind.ModuleKeyword);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Syntactic Diagnostics for file '/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts':
2-
/tests/cases/fourslash/a.js(1,11): error TS1176: Interface declaration cannot have 'implements' clause.
2+
/tests/cases/fourslash/a.js(1,11): error TS8006: 'interface' declarations can only be used in TypeScript files.
33

44

55
==== /tests/cases/fourslash/a.js (1 errors) ====
66
interface I { }
77
~
8-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
8+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.

tests/baselines/reference/jsDeclarationsInterfaces.errors.txt

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
tests/cases/conformance/jsdoc/declarations/index.js(4,18): error TS1176: Interface declaration cannot have 'implements' clause.
2-
tests/cases/conformance/jsdoc/declarations/index.js(6,18): error TS1176: Interface declaration cannot have 'implements' clause.
3-
tests/cases/conformance/jsdoc/declarations/index.js(10,18): error TS1176: Interface declaration cannot have 'implements' clause.
4-
tests/cases/conformance/jsdoc/declarations/index.js(31,11): error TS1176: Interface declaration cannot have 'implements' clause.
5-
tests/cases/conformance/jsdoc/declarations/index.js(35,11): error TS1176: Interface declaration cannot have 'implements' clause.
6-
tests/cases/conformance/jsdoc/declarations/index.js(39,18): error TS1176: Interface declaration cannot have 'implements' clause.
7-
tests/cases/conformance/jsdoc/declarations/index.js(43,18): error TS1176: Interface declaration cannot have 'implements' clause.
8-
tests/cases/conformance/jsdoc/declarations/index.js(45,18): error TS1176: Interface declaration cannot have 'implements' clause.
9-
tests/cases/conformance/jsdoc/declarations/index.js(49,18): error TS1176: Interface declaration cannot have 'implements' clause.
10-
tests/cases/conformance/jsdoc/declarations/index.js(53,18): error TS1176: Interface declaration cannot have 'implements' clause.
11-
tests/cases/conformance/jsdoc/declarations/index.js(57,18): error TS1176: Interface declaration cannot have 'implements' clause.
12-
tests/cases/conformance/jsdoc/declarations/index.js(61,18): error TS1176: Interface declaration cannot have 'implements' clause.
13-
tests/cases/conformance/jsdoc/declarations/index.js(65,18): error TS1176: Interface declaration cannot have 'implements' clause.
14-
tests/cases/conformance/jsdoc/declarations/index.js(67,18): error TS1176: Interface declaration cannot have 'implements' clause.
15-
tests/cases/conformance/jsdoc/declarations/index.js(71,18): error TS1176: Interface declaration cannot have 'implements' clause.
16-
tests/cases/conformance/jsdoc/declarations/index.js(75,18): error TS1176: Interface declaration cannot have 'implements' clause.
17-
tests/cases/conformance/jsdoc/declarations/index.js(80,18): error TS1176: Interface declaration cannot have 'implements' clause.
18-
tests/cases/conformance/jsdoc/declarations/index.js(84,18): error TS1176: Interface declaration cannot have 'implements' clause.
19-
tests/cases/conformance/jsdoc/declarations/index.js(87,18): error TS1176: Interface declaration cannot have 'implements' clause.
20-
tests/cases/conformance/jsdoc/declarations/index.js(91,18): error TS1176: Interface declaration cannot have 'implements' clause.
21-
tests/cases/conformance/jsdoc/declarations/index.js(95,18): error TS1176: Interface declaration cannot have 'implements' clause.
22-
tests/cases/conformance/jsdoc/declarations/index.js(100,18): error TS1176: Interface declaration cannot have 'implements' clause.
23-
tests/cases/conformance/jsdoc/declarations/index.js(105,18): error TS1176: Interface declaration cannot have 'implements' clause.
24-
tests/cases/conformance/jsdoc/declarations/index.js(107,18): error TS1176: Interface declaration cannot have 'implements' clause.
25-
tests/cases/conformance/jsdoc/declarations/index.js(111,18): error TS1176: Interface declaration cannot have 'implements' clause.
26-
tests/cases/conformance/jsdoc/declarations/index.js(115,18): error TS1176: Interface declaration cannot have 'implements' clause.
1+
tests/cases/conformance/jsdoc/declarations/index.js(4,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
2+
tests/cases/conformance/jsdoc/declarations/index.js(6,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
3+
tests/cases/conformance/jsdoc/declarations/index.js(10,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
4+
tests/cases/conformance/jsdoc/declarations/index.js(31,11): error TS8006: 'interface' declarations can only be used in TypeScript files.
5+
tests/cases/conformance/jsdoc/declarations/index.js(35,11): error TS8006: 'interface' declarations can only be used in TypeScript files.
6+
tests/cases/conformance/jsdoc/declarations/index.js(39,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
7+
tests/cases/conformance/jsdoc/declarations/index.js(43,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
8+
tests/cases/conformance/jsdoc/declarations/index.js(45,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
9+
tests/cases/conformance/jsdoc/declarations/index.js(49,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
10+
tests/cases/conformance/jsdoc/declarations/index.js(53,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
11+
tests/cases/conformance/jsdoc/declarations/index.js(57,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
12+
tests/cases/conformance/jsdoc/declarations/index.js(61,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
13+
tests/cases/conformance/jsdoc/declarations/index.js(65,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
14+
tests/cases/conformance/jsdoc/declarations/index.js(67,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
15+
tests/cases/conformance/jsdoc/declarations/index.js(71,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
16+
tests/cases/conformance/jsdoc/declarations/index.js(75,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
17+
tests/cases/conformance/jsdoc/declarations/index.js(80,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
18+
tests/cases/conformance/jsdoc/declarations/index.js(84,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
19+
tests/cases/conformance/jsdoc/declarations/index.js(87,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
20+
tests/cases/conformance/jsdoc/declarations/index.js(91,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
21+
tests/cases/conformance/jsdoc/declarations/index.js(95,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
22+
tests/cases/conformance/jsdoc/declarations/index.js(100,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
23+
tests/cases/conformance/jsdoc/declarations/index.js(105,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
24+
tests/cases/conformance/jsdoc/declarations/index.js(107,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
25+
tests/cases/conformance/jsdoc/declarations/index.js(111,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
26+
tests/cases/conformance/jsdoc/declarations/index.js(115,18): error TS8006: 'interface' declarations can only be used in TypeScript files.
2727

2828

2929
==== tests/cases/conformance/jsdoc/declarations/index.js (26 errors) ====
@@ -32,17 +32,17 @@ tests/cases/conformance/jsdoc/declarations/index.js(115,18): error TS1176: Inter
3232

3333
export interface A {}
3434
~
35-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
35+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
3636

3737
export interface B {
3838
~
39-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
39+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
4040
cat: string;
4141
}
4242

4343
export interface C<T, U> {
4444
~
45-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
45+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
4646
field: T & U;
4747
optionalField?: T;
4848
readonly readonlyField: T & U;
@@ -65,135 +65,135 @@ tests/cases/conformance/jsdoc/declarations/index.js(115,18): error TS1176: Inter
6565

6666
interface G {}
6767
~
68-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
68+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
6969

7070
export { G };
7171

7272
interface HH {}
7373
~~
74-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
74+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
7575

7676
export { HH as H };
7777

7878
export interface I {}
7979
~
80-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
80+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
8181
export { I as II };
8282

8383
export { J as JJ };
8484
export interface J {}
8585
~
86-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
86+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
8787

8888
export interface K extends I,J {
8989
~
90-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
90+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
9191
x: string;
9292
}
9393

9494
export interface L extends K {
9595
~
96-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
96+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
9797
y: string;
9898
}
9999

100100
export interface M<T> {
101101
~
102-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
102+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
103103
field: T;
104104
}
105105

106106
export interface N<U> extends M<U> {
107107
~
108-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
108+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
109109
other: U;
110110
}
111111

112112
export interface O {
113113
~
114-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
114+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
115115
[idx: string]: string;
116116
}
117117

118118
export interface P extends O {}
119119
~
120-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
120+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
121121

122122
export interface Q extends O {
123123
~
124-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
124+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
125125
[idx: string]: "ok";
126126
}
127127

128128
export interface R extends O {
129129
~
130-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
130+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
131131
[idx: number]: "ok";
132132
}
133133

134134
export interface S extends O {
135135
~
136-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
136+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
137137
[idx: string]: "ok";
138138
[idx: number]: never;
139139
}
140140

141141
export interface T {
142142
~
143-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
143+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
144144
[idx: number]: string;
145145
}
146146

147147
export interface U extends T {}
148148
~
149-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
149+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
150150

151151

152152
export interface V extends T {
153153
~
154-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
154+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
155155
[idx: string]: string;
156156
}
157157

158158
export interface W extends T {
159159
~
160-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
160+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
161161
[idx: number]: "ok";
162162
}
163163

164164
export interface X extends T {
165165
~
166-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
166+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
167167
[idx: string]: string;
168168
[idx: number]: "ok";
169169
}
170170

171171
export interface Y {
172172
~
173-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
173+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
174174
[idx: string]: {x: number};
175175
[idx: number]: {x: number, y: number};
176176
}
177177

178178
export interface Z extends Y {}
179179
~
180-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
180+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
181181

182182
export interface AA extends Y {
183183
~~
184-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
184+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
185185
[idx: string]: {x: number, y: number};
186186
}
187187

188188
export interface BB extends Y {
189189
~~
190-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
190+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
191191
[idx: number]: {x: 0, y: 0};
192192
}
193193

194194
export interface CC extends Y {
195195
~~
196-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
196+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.
197197
[idx: string]: {x: number, y: number};
198198
[idx: number]: {x: 0, y: 0};
199199
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
22
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
3-
tests/cases/compiler/a.js(1,11): error TS1176: Interface declaration cannot have 'implements' clause.
3+
tests/cases/compiler/a.js(1,11): error TS8006: 'interface' declarations can only be used in TypeScript files.
44

55

66
!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
77
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
88
==== tests/cases/compiler/a.js (1 errors) ====
99
interface I { }
1010
~
11-
!!! error TS1176: Interface declaration cannot have 'implements' clause.
11+
!!! error TS8006: 'interface' declarations can only be used in TypeScript files.

0 commit comments

Comments
 (0)