-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Omit type aliases when compiling TS #474
Comments
One workaround for your code is to instead write
to make it explicit that you want just a type alias. |
Thanks for reporting this issue, and thanks to @evmar for providing more details. I also wanted to ask: why not use a Also, does this code compile without errors when isolatedModules is enabled? That flag is designed to prohibit TypeScript features that would interfere with tools that compile each TypeScript file independently such as esbuild and I think also Parcel and Babel. You should probably have It would be interesting to see a full self-contained code sample that reproduces the problem. I don't have enough information from just this issue description to know what an appropriate fix could be, or even if it's possible to fix in a tool like esbuild that doesn't replicate TypeScript's type system. |
I looked more into this. It looks like it might be possible, although really hard, to get this to work for namespaces within the same file. Solving this basically involves building a mini type system of namespaces and import aliases and resolving references across them. From what I understand, getting this right might not require replicating TypeScript's full type system. However, it seems like this feature is most often used for import aliases across files, which is not how esbuild works anyway. There is no way that will work with esbuild since esbuild converts each TypeScript file to JavaScript in isolation. Unfortunately it looks like TypeScript doesn't prevent these cross-file import aliases even when Right now I'm thinking about potentially removing support for the |
I often use type aliases in my typescript files:
import Vector2Like = Types.Math.Vector2Like
after transpiling with esbuild it becomes:
var Vector2Like = Types.Math.Vector2Like
The issue is that
Types.Math.Vector2Like
exists only in the type space, there is noTypes
object in the runtime. And I get an errorUncaught TypeError: Cannot read property 'Math' of undefined
.Was it intentionally designed this way? If so - is there any way to fix it?
Thanks in advance!
The text was updated successfully, but these errors were encountered: