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

typescript-estree seems to be using a default import that doesn't exist #335

Closed
deifactor opened this issue Mar 7, 2019 · 11 comments
Closed
Labels
documentation Documentation ("docs") that needs adding/updating good first issue Good for newcomers has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@deifactor
Copy link

My dependencies:

  "dependencies": {
    "@typescript-eslint/typescript-estree": "^1.4.2",
    "typescript": "^3.3.3333"
  }

I have a file containing the single line

import * as tsParser from "@typescript-eslint/typescript-estree";

which fails to typecheck:

node_modules/@typescript-eslint/typescript-estree/dist/ts-nodes.d.ts:1:8 - error TS1192: Module '[redacted]/node_modules/typescript/lib/typescript"' has no default export.

1 import ts from 'typescript';
         ~~

It works if I enable allowSyntheticDefaultImports in my tsconfig.json, but it might be better to just import * as ts from 'typescript' instead.

package version
@typescript-eslint/typescript-estree 1.4.2
TypeScript 3.3.3333
node v11.7.0
npm 6.7.0
@deifactor deifactor added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for team members to take a look labels Mar 7, 2019
@bradzacher
Copy link
Member

You need to turn on synthetic default imports for it to work.

@deifactor
Copy link
Author

Would it make sense to change the import so consumers don't need synthetic default imports?

@bradzacher
Copy link
Member

Certainly someone could take a look, but it's worth noting that not all npm packages support non-synthetic default imports, so it may actually be required.

Also worth noting that we haven't spent any time optimising any of the types across the repo for consumption outside of the repo.

Related: #330

@bradzacher bradzacher added good first issue Good for newcomers documentation Documentation ("docs") that needs adding/updating and removed triage Waiting for team members to take a look labels Mar 12, 2019
@adidahiya
Copy link

esModuleInterop + allowSyntheticDefaultImports are the recommended standard options in the TS ecosystem now, see the TS 2.7 release notes, so I don't think any semantic change should be made here

@deifactor
Copy link
Author

That's fair. I know relatively little about what would need to be changed to make this work, and whether that'd break other users.

@bradzacher
Copy link
Member

@adidahiya - whilst they are recommended, a lot of projects don't use them because they're not the default (yet?). So it might make sense to support not using them if it's not too much effort.

I haven't looked into it, but I think that it should be as simple as:

- import ts from 'typescript';
+ import * as ts from 'typescript';

If it's not that easy then I'll definitely drop it and instead opt for documenting the requirement on the options.

@adidahiya
Copy link

adidahiya commented Mar 12, 2019

@bradzacher the problem is that it's hard to support both export styles in a published library, and I'd rather lean towards the future-facing syntax

edit: Yes, the code transformation for the breaking API change is as simple as that

@deifactor
Copy link
Author

If this would break people who don't use allowSyntheticDefaultImports then I agree that it's reasonable to just document 'by the way, you'll need this' on the README.md or someplace like it.

@j-f1
Copy link
Contributor

j-f1 commented Mar 12, 2019

That change should work either way.

@bradzacher bradzacher added the has pr there is a PR raised to close this label Apr 25, 2019
@crhistianramirez
Copy link

Looks like this issue should be closed? There's a merged PR from back in April

@j-f1
Copy link
Contributor

j-f1 commented Jul 11, 2019

Thanks @crhistianramirez!

@j-f1 j-f1 closed this as completed Jul 11, 2019
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating good first issue Good for newcomers has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

No branches or pull requests

5 participants