-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
type-only import prevents declaration of a value with the same name #40583
Comments
This is correct, import type { Foo as _Foo } from "./Foo";
type Foo = _Foo;
function Foo(): Foo {
return {
name: "index.ts"
};
}
Foo(); or type Foo = import("./Foo").Foo;
function Foo(): Foo {
return {
name: "index.ts"
};
}
Foo(); |
Letting @andrewbranch correct me if I'm mistaken though |
You got it right 👍 |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Sorry for bringing this up after four years, but I'm interested in what way can |
The best way to understand this is that the correct interpretation isn't "Import the type meaning of // foo.ts
export class Foo {
static x = "bar";
} You can import it elsewhere and use it as a value, in type positions: import type { Foo } from "./foo.js";
function something(f: typeof Foo) { // <- *value* reference on Foo
return f.x;
} |
Aha. So this is more a feature for avoiding unnecessary imports in the built code. If I want to use a value |
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
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:Playground Link: https://codesandbox.io/s/wizardly-chatelet-h8zkg?file=/src/index.ts
Related Issues: #35200
cc: @andrewbranch
The text was updated successfully, but these errors were encountered: