Skip to content

Commit 90b304a

Browse files
authored
Merge pull request #30786 from Microsoft/always-check-class-extends
Always check extends clause of classes
2 parents 86f0d4b + 1218f29 commit 90b304a

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
@@ -27439,6 +27439,11 @@ namespace ts {
2743927439
if (languageVersion < ScriptTarget.ES2015) {
2744027440
checkExternalEmitHelpers(baseTypeNode.parent, ExternalEmitHelpers.Extends);
2744127441
}
27442+
// check both @extends and extends if both are specified.
27443+
const extendsNode = getClassExtendsHeritageElement(node);
27444+
if (extendsNode && extendsNode !== baseTypeNode) {
27445+
checkExpression(extendsNode.expression);
27446+
}
2744227447

2744327448
const baseTypes = getBaseTypes(type);
2744427449
if (baseTypes.length && produceDiagnostics) {
@@ -27447,10 +27452,6 @@ namespace ts {
2744727452
const staticBaseType = getApparentType(baseConstructorType);
2744827453
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
2744927454
checkSourceElement(baseTypeNode.expression);
27450-
const extendsNode = getClassExtendsHeritageElement(node);
27451-
if (extendsNode && extendsNode !== baseTypeNode) {
27452-
checkExpression(extendsNode.expression);
27453-
}
2745427455
if (some(baseTypeNode.typeArguments)) {
2745527456
forEach(baseTypeNode.typeArguments, checkSourceElement);
2745627457
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)