Skip to content
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9755,7 +9755,7 @@ func (c *Checker) invocationErrorRecovery(apparentType *Type, kind SignatureKind
// Create a diagnostic on the originating import if possible onto which we can attach a quickfix
// 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
if importNode != nil && !ast.IsImportCall(importNode) {
sigs := c.getSignaturesOfType(c.getTypeOfSymbol(c.valueSymbolLinks.Get(apparentType.symbol).target), kind)
sigs := c.getSignaturesOfType(c.getTypeOfSymbol(c.exportTypeLinks.Get(apparentType.symbol).target), kind)
if len(sigs) == 0 {
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
index.ts(2,1): error TS2349: This expression is not callable.
Type '{ default: () => void; }' has no call signatures.


==== foo.d.ts (0 errors) ====
declare function foo(): void;
declare namespace foo {}
export = foo;
==== index.ts (1 errors) ====
import * as foo from "./foo";
foo()
~~~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type '{ default: () => void; }' has no call signatures.
!!! 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/invocationErrorRecovery.ts] ////

=== foo.d.ts ===
declare function foo(): void;
>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29))

declare namespace foo {}
>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29))

export = foo;
>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29))

=== index.ts ===
import * as foo from "./foo";
>foo : Symbol(foo, Decl(index.ts, 0, 6))

foo()
>foo : Symbol(foo, Decl(index.ts, 0, 6))

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/invocationErrorRecovery.ts] ////

=== foo.d.ts ===
declare function foo(): void;
>foo : () => void

declare namespace foo {}
export = foo;
>foo : () => void

=== index.ts ===
import * as foo from "./foo";
>foo : { default: () => void; }

foo()
>foo() : any
>foo : { default: () => void; }

11 changes: 11 additions & 0 deletions testdata/tests/cases/compiler/invocationErrorRecovery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @module: nodenext
// @target: esnext
// @strict: true
// @noEmit: true
// @filename: foo.d.ts
declare function foo(): void;
declare namespace foo {}
export = foo;
// @filename: index.ts
import * as foo from "./foo";
foo()