-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
TypeScript Version: 4.1.0-dev.20200915
Search Terms: ts1361 type-only import type 'Foo' cannot be used as a value because it was imported using 'import type'.
Code
import type { Foo } from "./Foo";
function Foo(): Foo {
return {
name: "index.ts"
};
}
Foo(); // 'Foo' cannot be used as a value because it was imported using 'import type'.ts(1361)Expected behavior: Since the import type only creates a symbol in the type realm, I expect to be able to create the same symbol in the value realm without conflict. Especially since it's possible to declare the same symbol as both a type and value from within a single file.
Actual behavior: An error is raised: 'Foo' cannot be used as a value because it was imported using 'import type'.ts(1361), which makes this behavior seem very much intended, though that seems to violate the feature's stated intent. From the description of the feature's Type semantics from #35200:
If the symbol does have a value side, name resolution for that symbol will see only the type side.
Playground Link: https://codesandbox.io/s/wizardly-chatelet-h8zkg?file=/src/index.ts
Related Issues: #35200
cc: @andrewbranch