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

allowSyntheticImports should do the emit for synthetic import as well #9562

Closed
basarat opened this issue Jul 7, 2016 · 5 comments
Closed
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@basarat
Copy link
Contributor

basarat commented Jul 7, 2016

I just migrated a largish project from Babel to TypeScript. This was the bulk of the changes, i.e. going from import React from "react" to import * as React from "react".

I know that babel definitely did a bad thing by allowing people to use export = as the default import http://stackoverflow.com/a/37152481/390330

however we already support type checking for that with allowSyntheticImports. Why not add the transpile for that as well. Reason being that a lot of JS code is being (even if wrongly) written in import fs from "fs" style (e.g webpack docs : https://gist.github.com/sokra/27b24881210b56bbaff7) and getting to all these people and telling them to stop doing it is no longer a possibility, so if we want a simpler 1-1 JS thats out there to TS migration this would greatly help

🌹

PS : I did a video with allowJs https://www.youtube.com/watch?v=gmKXXI_ck7w Love you guys ❤️

@DanielRosenwasser DanielRosenwasser added the Suggestion An idea for TypeScript label Jul 7, 2016
@DanielRosenwasser
Copy link
Member

I know that babel definitely did a bad thing by allowing people to use export = as the default import

Actually, I think that this was the right thing. The wrong thing was that both Babel and TypeScript allowed named imports from it. Check out the following discussion: nodejs/node-eps#26 (comment)

@basarat
Copy link
Contributor Author

basarat commented Jul 7, 2016

Actually, I think that this was the right thing

Thanks. All the more reason to have TypeScript transpile it then 🌹 :)

More : the issue is made worse by the fact that if you do stuff like declare module "foo"; (a new shorthand) then import foo from "foo" will compile fine (irrespective of synthetic import settings) and then you have a runtime error that TypeScript never caught :-/ :cry: :crying_cat_face: :sob: (ノಥ,_」ಥ)ノ彡┻━┻

@myknbani
Copy link

myknbani commented Apr 2, 2017

dumb question..

Does this mean that allowSyntheticDefaultImports is sort of useless until this issue is fixed?

I tried the Babelish import path from 'path' and path is undefined. ✌️

(EDIT: VS Code however is able to provide intellisense for path)

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 3, 2017

Does this mean that allowSyntheticDefaultImports is sort of useless until this issue is fixed?

No, tools like Babel, Webpack, and SystemJS do this automatically. You'll often use TypeScript in conjunction with one of them.

@RyanCavanaugh RyanCavanaugh added the In Discussion Not yet reached consensus label Apr 3, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Feb 8, 2018

--esModuleInterop should cover this request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants