mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
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.
This commit is contained in:
@@ -27424,6 +27424,11 @@ namespace ts {
|
||||
if (languageVersion < ScriptTarget.ES2015) {
|
||||
checkExternalEmitHelpers(baseTypeNode.parent, ExternalEmitHelpers.Extends);
|
||||
}
|
||||
// check both @extends and extends if both are specified.
|
||||
const extendsNode = getClassExtendsHeritageElement(node);
|
||||
if (extendsNode && extendsNode !== baseTypeNode) {
|
||||
checkExpression(extendsNode.expression);
|
||||
}
|
||||
|
||||
const baseTypes = getBaseTypes(type);
|
||||
if (baseTypes.length && produceDiagnostics) {
|
||||
@@ -27432,10 +27437,6 @@ namespace ts {
|
||||
const staticBaseType = getApparentType(baseConstructorType);
|
||||
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
|
||||
checkSourceElement(baseTypeNode.expression);
|
||||
const extendsNode = getClassExtendsHeritageElement(node);
|
||||
if (extendsNode && extendsNode !== baseTypeNode) {
|
||||
checkExpression(extendsNode.expression);
|
||||
}
|
||||
if (some(baseTypeNode.typeArguments)) {
|
||||
forEach(baseTypeNode.typeArguments, checkSourceElement);
|
||||
for (const constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode)) {
|
||||
|
||||
17
tests/baselines/reference/extendsTagEmit.errors.txt
Normal file
17
tests/baselines/reference/extendsTagEmit.errors.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
tests/cases/conformance/jsdoc/main.js(2,15): error TS2304: Cannot find name 'Mismatch'.
|
||||
tests/cases/conformance/jsdoc/main.js(2,15): error TS8023: JSDoc '@extends Mismatch' does not match the 'extends B' clause.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/super.js (0 errors) ====
|
||||
export class B { }
|
||||
|
||||
==== tests/cases/conformance/jsdoc/main.js (2 errors) ====
|
||||
import { B } from './super'
|
||||
/** @extends {Mismatch} */
|
||||
~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'Mismatch'.
|
||||
~~~~~~~~
|
||||
!!! error TS8023: JSDoc '@extends Mismatch' does not match the 'extends B' clause.
|
||||
class C extends B { }
|
||||
|
||||
|
||||
20
tests/baselines/reference/extendsTagEmit.js
Normal file
20
tests/baselines/reference/extendsTagEmit.js
Normal file
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/conformance/jsdoc/extendsTagEmit.ts] ////
|
||||
|
||||
//// [super.js]
|
||||
export class B { }
|
||||
|
||||
//// [main.js]
|
||||
import { B } from './super'
|
||||
/** @extends {Mismatch} */
|
||||
class C extends B { }
|
||||
|
||||
|
||||
|
||||
//// [super.js]
|
||||
export class B {
|
||||
}
|
||||
//// [main.js]
|
||||
import { B } from './super';
|
||||
/** @extends {Mismatch} */
|
||||
class C extends B {
|
||||
}
|
||||
14
tests/baselines/reference/extendsTagEmit.symbols
Normal file
14
tests/baselines/reference/extendsTagEmit.symbols
Normal file
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/conformance/jsdoc/super.js ===
|
||||
export class B { }
|
||||
>B : Symbol(B, Decl(super.js, 0, 0))
|
||||
|
||||
=== tests/cases/conformance/jsdoc/main.js ===
|
||||
import { B } from './super'
|
||||
>B : Symbol(B, Decl(main.js, 0, 8))
|
||||
|
||||
/** @extends {Mismatch} */
|
||||
class C extends B { }
|
||||
>C : Symbol(C, Decl(main.js, 0, 27))
|
||||
>B : Symbol(B, Decl(main.js, 0, 8))
|
||||
|
||||
|
||||
14
tests/baselines/reference/extendsTagEmit.types
Normal file
14
tests/baselines/reference/extendsTagEmit.types
Normal file
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/conformance/jsdoc/super.js ===
|
||||
export class B { }
|
||||
>B : B
|
||||
|
||||
=== tests/cases/conformance/jsdoc/main.js ===
|
||||
import { B } from './super'
|
||||
>B : typeof B
|
||||
|
||||
/** @extends {Mismatch} */
|
||||
class C extends B { }
|
||||
>C : C
|
||||
>B : typeof B
|
||||
|
||||
|
||||
12
tests/cases/conformance/jsdoc/extendsTagEmit.ts
Normal file
12
tests/cases/conformance/jsdoc/extendsTagEmit.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @target: esnext
|
||||
// @outDir: out
|
||||
// @Filename: super.js
|
||||
export class B { }
|
||||
|
||||
// @Filename: main.js
|
||||
import { B } from './super'
|
||||
/** @extends {Mismatch} */
|
||||
class C extends B { }
|
||||
|
||||
Reference in New Issue
Block a user