Skip to content

Commit 8bf36dd

Browse files
authored
Fix crash in invocationErrorRecovery function (#1944)
1 parent def283d commit 8bf36dd

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9755,7 +9755,7 @@ func (c *Checker) invocationErrorRecovery(apparentType *Type, kind SignatureKind
97559755
// Create a diagnostic on the originating import if possible onto which we can attach a quickfix
97569756
// An import call expression cannot be rewritten into another form to correct the error - the only solution is to use `.default` at the use-site
97579757
if importNode != nil && !ast.IsImportCall(importNode) {
9758-
sigs := c.getSignaturesOfType(c.getTypeOfSymbol(c.valueSymbolLinks.Get(apparentType.symbol).target), kind)
9758+
sigs := c.getSignaturesOfType(c.getTypeOfSymbol(c.exportTypeLinks.Get(apparentType.symbol).target), kind)
97599759
if len(sigs) == 0 {
97609760
return
97619761
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
index.ts(2,1): error TS2349: This expression is not callable.
2+
Type '{ default: () => void; }' has no call signatures.
3+
4+
5+
==== foo.d.ts (0 errors) ====
6+
declare function foo(): void;
7+
declare namespace foo {}
8+
export = foo;
9+
==== index.ts (1 errors) ====
10+
import * as foo from "./foo";
11+
foo()
12+
~~~
13+
!!! error TS2349: This expression is not callable.
14+
!!! error TS2349: Type '{ default: () => void; }' has no call signatures.
15+
!!! related TS7038 index.ts:1:1: Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
16+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/invocationErrorRecovery.ts] ////
2+
3+
=== foo.d.ts ===
4+
declare function foo(): void;
5+
>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29))
6+
7+
declare namespace foo {}
8+
>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29))
9+
10+
export = foo;
11+
>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29))
12+
13+
=== index.ts ===
14+
import * as foo from "./foo";
15+
>foo : Symbol(foo, Decl(index.ts, 0, 6))
16+
17+
foo()
18+
>foo : Symbol(foo, Decl(index.ts, 0, 6))
19+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/invocationErrorRecovery.ts] ////
2+
3+
=== foo.d.ts ===
4+
declare function foo(): void;
5+
>foo : () => void
6+
7+
declare namespace foo {}
8+
export = foo;
9+
>foo : () => void
10+
11+
=== index.ts ===
12+
import * as foo from "./foo";
13+
>foo : { default: () => void; }
14+
15+
foo()
16+
>foo() : any
17+
>foo : { default: () => void; }
18+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @module: nodenext
2+
// @target: esnext
3+
// @strict: true
4+
// @noEmit: true
5+
// @filename: foo.d.ts
6+
declare function foo(): void;
7+
declare namespace foo {}
8+
export = foo;
9+
// @filename: index.ts
10+
import * as foo from "./foo";
11+
foo()

0 commit comments

Comments
 (0)