Skip to content

Commit dabf2a6

Browse files
committed
Always check extends clause of classes
Even if (1) @extends is provided and (2) we're not producing diagnostics. That's because we need to know whether the extends clause references an imported alias.
1 parent 0b3b4ea commit dabf2a6

File tree

6 files changed

+82
-4
lines changed

6 files changed

+82
-4
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27424,6 +27424,11 @@ namespace ts {
2742427424
if (languageVersion < ScriptTarget.ES2015) {
2742527425
checkExternalEmitHelpers(baseTypeNode.parent, ExternalEmitHelpers.Extends);
2742627426
}
27427+
// check both @extends and extends if both are specified.
27428+
const extendsNode = getClassExtendsHeritageElement(node);
27429+
if (extendsNode && extendsNode !== baseTypeNode) {
27430+
checkExpression(extendsNode.expression);
27431+
}
2742727432

2742827433
const baseTypes = getBaseTypes(type);
2742927434
if (baseTypes.length && produceDiagnostics) {
@@ -27432,10 +27437,6 @@ namespace ts {
2743227437
const staticBaseType = getApparentType(baseConstructorType);
2743327438
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
2743427439
checkSourceElement(baseTypeNode.expression);
27435-
const extendsNode = getClassExtendsHeritageElement(node);
27436-
if (extendsNode && extendsNode !== baseTypeNode) {
27437-
checkExpression(extendsNode.expression);
27438-
}
2743927440
if (some(baseTypeNode.typeArguments)) {
2744027441
forEach(baseTypeNode.typeArguments, checkSourceElement);
2744127442
for (const constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode)) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/jsdoc/main.js(2,15): error TS2304: Cannot find name 'Mismatch'.
2+
tests/cases/conformance/jsdoc/main.js(2,15): error TS8023: JSDoc '@extends Mismatch' does not match the 'extends B' clause.
3+
4+
5+
==== tests/cases/conformance/jsdoc/super.js (0 errors) ====
6+
export class B { }
7+
8+
==== tests/cases/conformance/jsdoc/main.js (2 errors) ====
9+
import { B } from './super'
10+
/** @extends {Mismatch} */
11+
~~~~~~~~
12+
!!! error TS2304: Cannot find name 'Mismatch'.
13+
~~~~~~~~
14+
!!! error TS8023: JSDoc '@extends Mismatch' does not match the 'extends B' clause.
15+
class C extends B { }
16+
17+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/conformance/jsdoc/extendsTagEmit.ts] ////
2+
3+
//// [super.js]
4+
export class B { }
5+
6+
//// [main.js]
7+
import { B } from './super'
8+
/** @extends {Mismatch} */
9+
class C extends B { }
10+
11+
12+
13+
//// [super.js]
14+
export class B {
15+
}
16+
//// [main.js]
17+
import { B } from './super';
18+
/** @extends {Mismatch} */
19+
class C extends B {
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/super.js ===
2+
export class B { }
3+
>B : Symbol(B, Decl(super.js, 0, 0))
4+
5+
=== tests/cases/conformance/jsdoc/main.js ===
6+
import { B } from './super'
7+
>B : Symbol(B, Decl(main.js, 0, 8))
8+
9+
/** @extends {Mismatch} */
10+
class C extends B { }
11+
>C : Symbol(C, Decl(main.js, 0, 27))
12+
>B : Symbol(B, Decl(main.js, 0, 8))
13+
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/super.js ===
2+
export class B { }
3+
>B : B
4+
5+
=== tests/cases/conformance/jsdoc/main.js ===
6+
import { B } from './super'
7+
>B : typeof B
8+
9+
/** @extends {Mismatch} */
10+
class C extends B { }
11+
>C : C
12+
>B : typeof B
13+
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @target: esnext
4+
// @outDir: out
5+
// @Filename: super.js
6+
export class B { }
7+
8+
// @Filename: main.js
9+
import { B } from './super'
10+
/** @extends {Mismatch} */
11+
class C extends B { }
12+

0 commit comments

Comments
 (0)