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

ES6 modules broken in 0.10.8 with Salsa #7006

Closed
egamma opened this issue Feb 10, 2016 · 13 comments
Closed

ES6 modules broken in 0.10.8 with Salsa #7006

egamma opened this issue Feb 10, 2016 · 13 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@egamma
Copy link
Member

egamma commented Feb 10, 2016

From @prashaantt on February 9, 2016 15:34

I'm loving the JSX support in the latest Code update, courtesy Salsa — thanks a ton for that! The thing is, I'm not ready to go all out on TS yet. Is it possible to just get the JSX auto-complete/IntelliSense support without running into issues like these:

image

image

Copied from original issue: microsoft/vscode#2848

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

From @prashaantt on February 9, 2016 16:1

I have been experimenting a bit and dropping a jsconfig.json in my project seems to do the trick and no longer shows these errors. Is that the way to achieve this?

I jumped too early. A jsconfig.json fixes the first error with the import but not the second one with the export.

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

From @tmkbry on February 9, 2016 16:20

@prashaantt I had the same problem, the jsconfig.json fixed it for me, thanks.

To the second problem, It doesn't show an error for me, maybe it's because I have this in my jsconfig.json:
{ "compilerOptions": { "target": "ES6" }, "exclude": [ "node_modules" ] }

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

From @prashaantt on February 9, 2016 16:29

@tmkbry I have a similar config as yours, plus the "module": "commonjs" inside compilerOptions, but I can't get rid of the squigglies on the export either way.

EDIT: I think ideally the module should be es6 but jsconfig.json reports an error for that, which otherwise is acceptable inside a tsconfig.json.

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

From @prashaantt on February 9, 2016 18:35

Ok, so this works:

export default function () { }

but this doesn't:

export default () => { }

Awesome!

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

From @prashaantt on February 9, 2016 18:37

(Perhaps I should leave this issue open, just in case there's anything the Code team can do to make this alt syntax work too.)

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

From @prashaantt on February 9, 2016 19:26

Another instance that I can't work around:

import { connect } from 'react-redux';

const mapStateToProps = (state) => { ... };

class App extends React.Component { ... }

export default connect(mapStateToProps)(App); // here be the relentless squiggly

The export throws the same error as before: 'export=' can only be used in a .ts file.

@egamma
Copy link
Member Author

egamma commented Feb 10, 2016

Extracted a separate issue for

I think ideally the module should be es6 but jsconfig.json reports an error for that, which otherwise is acceptable inside a tsconfig.json .

Moving to Salsa

@billti
Copy link
Member

billti commented Feb 10, 2016

There seems to be a few issues above. What is the specific problem here? Is it that ES6 should be the default module type? (which would be incompatible with the other request for CommonJS to be the default modules type)? Or is that export default doesn't work for arrow functions?

@prashaantt
Copy link

It's more like export default doesn't work for some cases.

Here are a few things that don't work:

const a = function () {}; // this could be whatever: object or function, arrow or not, anonymous or named

export default a;
export default () => { }
function myFunc() {};

export default myFunc();

These do work:

export const a = function () {}; // could be anything
export default function myFunc() {}; // anonymous is also ok
const a = function () {};

export { a };
const a = function () {};

module.exports = a;

@billti billti added Bug A bug in TypeScript Salsa labels Feb 10, 2016
@billti billti added this to the TypeScript 1.8.2 milestone Feb 10, 2016
@billti billti self-assigned this Feb 10, 2016
@billti
Copy link
Member

billti commented Feb 12, 2016

I just tried all the things above which state they don't work, using the latest release-1.8 build, and they all look fine for me with no errors (including the React/Redux pattern above). Can you try with the latest bits and see if this is still an issue? Else looks like we've addressed the above patterns.

Thanks!

screen shot 2016-02-12 at 10 50 59 am

screen shot 2016-02-12 at 10 51 26 am

@prashaantt
Copy link

@billti Thanks for looking into this.

As recommended in the release notes for VS Code, my error report was based on typescript@1.9.0-dev.20160128.

Per your request, I tried moving to the latest 1.8 release version on npm 1.8.0 and still see these errors. I then switched to typescript@next which currently gives me 1.9.0-dev.20160212 where all these errors indeed don't show up, so all looks good there.

But since you specifically asked me to check on 1.8 I'm wondering if its latest version is up on npm at all, because the currently 1.8.0 tagged version (2016-01-28T19:54:42.196Z) didn't fix these issues for me.

@billti
Copy link
Member

billti commented Feb 12, 2016

@prashaantt typescript@next is whatever is currently in the master branch, so glad to see it's fixed there too! Thanks for checking.

release-1.8 is the release we're about to ship. Once it forks from master, then it only gets a new release on NPM when we push it, so it can be a little behind (as it is currently). There should be a new (hopefully final 1.8) up there shortly though.

@billti billti closed this as completed Feb 12, 2016
@prashaantt
Copy link

Awesome, thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants