TS:1379 An import alias cannot reference a declaration that was exported using 'export type'
Bug Report
🔎 Search Terms
TS1379 An import alias cannot reference a declaration that was exported using 'export type'
🕗 Version & Regression Information
This has always been the behavior as far as I can tell (edit: tested on all versions listed in playground back to >3.7.5 (changed to export type {...} statement when needed))
⏯ Playground Link
Multi file: repro but I will show in playground.
Below are pictures that might be easier to parse
💻 Code
When annotated with type it errors
When not annotated with type it doesn't error:
🙁 Actual behavior
Exports of types annotated with type error while those not annotated as types do not error even though TS understand it is still a type.
🙂 Expected behavior
Honestly I don't know which of these behaviors is correct - this behavior could be completely intentional as well - intuitively I think these should match and I prefer the behavior with no errors but it is unclear to me if this is an emit issue? I'm sorry if this behavior is on purpose and I have wasted your time. Really appreciate the work!
It should be like:
//exporter.ts
type foo = {
thing: number;
}
export type foo
This should work expectedly. Otherwise, this is intentional. No worries!
I'm not sure I understand what you mean?
export type foo = {thing: number}
works I agree.
//exporter.ts
type foo = {
thing: number;
}
export type foo
is a syntax error no? I just don't understand the behavior. It's a very specific function in the checker
the error reporter:
the comment around the function that really does the check
I don't exactly understand why this is. If you don't have the time/think its to in the weeds to explain I totally understand! But I'm pretty curious as to why this is the behavior. I only encountered this corner because I wrote a little script to tag all of exports of types as typeOnly=true. (It's my understanding that this is good practice when ts_loader is set to transpileOnly)
There was a missing semicolon. You can't put type in curly brackets, I believe.
Here might be the issue(s):
-
TypeScript version: It's worth noting that TypeScript evolves over time, and there may be differences in behavior between different versions. It's possible that the behavior you're observing is specific to the version you're using.
-
Configuration or compiler options: The behavior of TypeScript can also be influenced by various compiler options and configuration settings. It's worth double-checking your project's TypeScript configuration files (such as tsconfig.json) to see if any specific settings might be affecting this behavior.
-
Bug or regression: While you mentioned that this behavior has always been consistent, it's still possible that there is an underlying bug or regression in TypeScript that causes this inconsistency. In such cases, it might be helpful to consult the TypeScript documentation, release notes, or community forums to see if there are any known issues related to import aliases and export type.
You can put type in curly brackets, it sets the boolean isTypeOnly in ExportSpecifier in the AST, the behavior is the same if isTypeOnly is set in an ExportDeclaration. I can check every version of TS, but this behavior is very specific to export declarations themselves (not statements branded with export) tied to import equals declarations - notably this is of course fine in non-importEqualsDeclarations import statements.
Yea so I tested back to 3.7.5 (going through the list playground versions locally) where it was a syntax error on my export type statement - This has always been the behavior (at least on some tsconfig setting, I don't know what I would change around to check).
Not sure how to help. Is AI service available in your current country?
And what about your tsconfig.json?
What causes you to keep disliking my answers, @guillaumebrunerie?
@gooddavvy They look AI-generated and particularly unhelpful.
The behavior observed in TypeScript, where exports of type-annotated types result in errors while un-annotated ones do not, is unclear whether this is intentional or a bug/limitation. This behavior has been consistent across different versions of TypeScript, including up to version 3.7.5.
1 answer looks AI-generated. Just 1 @guillaumebrunerie
Since you have imported * as core, just make a normal definition type thing = core.foo;