Merge pull request #30786 from Microsoft/always-check-class-extends
Always check extends clause of classes
This commit is contained in:
commit
90b304aa5e
|
@ -27439,6 +27439,11 @@ namespace ts {
|
||||||
if (languageVersion < ScriptTarget.ES2015) {
|
if (languageVersion < ScriptTarget.ES2015) {
|
||||||
checkExternalEmitHelpers(baseTypeNode.parent, ExternalEmitHelpers.Extends);
|
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);
|
const baseTypes = getBaseTypes(type);
|
||||||
if (baseTypes.length && produceDiagnostics) {
|
if (baseTypes.length && produceDiagnostics) {
|
||||||
|
@ -27447,10 +27452,6 @@ namespace ts {
|
||||||
const staticBaseType = getApparentType(baseConstructorType);
|
const staticBaseType = getApparentType(baseConstructorType);
|
||||||
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
|
checkBaseTypeAccessibility(staticBaseType, baseTypeNode);
|
||||||
checkSourceElement(baseTypeNode.expression);
|
checkSourceElement(baseTypeNode.expression);
|
||||||
const extendsNode = getClassExtendsHeritageElement(node);
|
|
||||||
if (extendsNode && extendsNode !== baseTypeNode) {
|
|
||||||
checkExpression(extendsNode.expression);
|
|
||||||
}
|
|
||||||
if (some(baseTypeNode.typeArguments)) {
|
if (some(baseTypeNode.typeArguments)) {
|
||||||
forEach(baseTypeNode.typeArguments, checkSourceElement);
|
forEach(baseTypeNode.typeArguments, checkSourceElement);
|
||||||
for (const constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments, baseTypeNode)) {
|
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 { }
|
||||||
|
|
Loading…
Reference in a new issue