-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Legacy importing type from namespace is not supported #2468
Comments
I'm not sure whether esbuild should treat both Here's the babel behavior: // input
import { Scope } from 'eslint'
import Variable = Scope.Variable
let a: Variable
// output
var Variable = Scope.Variable;
let a;
export {}; // input
import { Scope } from 'eslint'
import Variable = Scope.Variable
let a: Variable
// output
import { Scope } from "eslint";
const Variable = Scope.Variable;
let a; esbuild, but annotate // input
import { Scope } from 'eslint'
import type Variable = Scope.Variable
let a: Variable
// output
let a; Interesting, sucrase seems to have done what you want: // input
import { Scope } from 'eslint'
import Variable = Scope.Variable
let a: Variable
// output
let a; |
It's about compatibility with TypeScript itself import type Variable = Scope.Variable it's invalid TypeScript syntax AFAIK. |
Yep, I've just updated comments above. So It's hard to say which is right here, maybe babel is wrong too. |
Yep, I'm going raise an issue on Babel also. |
One unusual thing about esbuild is that by default, the transform API does not assume that the provided input is a complete module. This allows for you to either run the output in the global scope or to add additional code after the output to form a module. For example, this can be used to implement TypeScript support for Svelte: #604. So this import could hypothetically be of a variable, not a type, in which case it would need to be kept in this scenario. However, I should be able to make this work if you enable tree shaking, either explicitly with |
If you only want a type, you can just use |
@evanw The problem is the source codes are out controlled from us. 😅I'm using a git submodule. |
Doesn't this mean that This behavior is a little strange to me because in the following code snippet, if However, when tree-shaking enabled, the erroneous code is removed and the module is "fixed". import { someNamespace } from './some-file'
import bar = someNamespace.foo; I should note this is only a problem when transforming to CJS. In ESM, the import statement will assert that |
When in one-file-at-a-time mode, the official TypeScript compiler always removes Technically I suppose I should also remove the import statement itself if all import assignments are removed, so I guess I could reopen this issue for that purpose. Removing an import is different than tree shaking an unused variable though. So this would mean changing esbuild to just always do the removal independent of whether tree shaking is enabled or not. |
related privatenumber/tsx#83
The text was updated successfully, but these errors were encountered: