Skip to content
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

import type from from "foo" #56376

Closed
magic-akari opened this issue Nov 13, 2023 · 3 comments · Fixed by #56385
Closed

import type from from "foo" #56376

magic-akari opened this issue Nov 13, 2023 · 3 comments · Fixed by #56385
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@magic-akari
Copy link
Contributor

🔎 Search Terms

  • type import
  • parser
  • import type from from

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAMyhEjmoERQKYEMDGMGA3HAPRlwQDWAUKJLHDAJ5jZwAeaKcWehEuUo164aPFbseqJL34EipCnDC4oAZw7YoyKEA

💻 Code

import from from "react"; // ok
import type x from "react"; // ok
import type from from "react"; // parse error

🙁 Actual behavior

parse error

🙂 Expected behavior

I have merely observed its inconsistency, without discerning whether it is by design or a bug.

Additional information about the issue

No response

@fatcerberus
Copy link

Looks like the parser is interpreting type as an identifier on line 3 and then choking when it sees the second from.

@evanw
Copy link
Contributor

evanw commented Nov 18, 2023

There's still a problem with import type from = require('foo'): (playground link). That seems like a bug if it's expected that from is allowed to be the name of an imported type. Should that be fixed as part of this issue as well?

For context, I'm commenting here because I was linked to this bug from esbuild's issue tracker, and I need to figure out how to handle this kind of type syntax in esbuild.

Edit: Also import type from, {foo} from "foo" doesn't work either: (playground link). Neither does import type from, * as foo from "foo": (playground link). Never mind. It looks like if it did work, the TypeScript compiler would just say "A type-only import can specify a default import or named bindings, but not both." So it should arguably be a different error but it's still an error, so it's still invalid syntax.

@andrewbranch
Copy link
Member

Yes, import type from = require('foo') should be legal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants