Skip to content

Fix bug: Report errors on extends expression in JS even if an @augments tag is present #18854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4917,6 +4917,8 @@ namespace ts {
*/
function getBaseConstructorTypeOfClass(type: InterfaceType): Type {
if (!type.resolvedBaseConstructorType) {
const decl = <ClassLikeDeclaration>type.symbol.valueDeclaration;
const extended = getClassExtendsHeritageClauseElement(decl);
const baseTypeNode = getBaseTypeNodeOfClass(type);
if (!baseTypeNode) {
return type.resolvedBaseConstructorType = undefinedType;
Expand All @@ -4925,6 +4927,10 @@ namespace ts {
return unknownType;
}
const baseConstructorType = checkExpression(baseTypeNode.expression);
if (extended && baseTypeNode !== extended) {
Debug.assert(!extended.typeArguments); // Because this is in a JS file, and baseTypeNode is in an @extends tag
checkExpression(extended.expression);
}
if (baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
// Resolving the members of a class requires us to resolve the base class of that class.
// We force resolution here such that we catch circularities now.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/a.js(3,17): error TS2304: Cannot find name 'err'.


==== /a.js (1 errors) ====
class A {}
/** @augments A */
class B extends err() {}
~~~
!!! error TS2304: Cannot find name 'err'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== /a.js ===
class A {}
>A : Symbol(A, Decl(a.js, 0, 0))

/** @augments A */
class B extends err() {}
>B : Symbol(B, Decl(a.js, 0, 10))

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== /a.js ===
class A {}
>A : A

/** @augments A */
class B extends err() {}
>B : B
>err() : A
>err : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: /a.js
class A {}
/** @augments A */
class B extends err() {}