-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 import/named with types in d.ts
#1341
Comments
Struggling with a similar issue and import { RequestHandler, Request } from 'express-serve-static-core'; results in an error: 8:41 error Unable to resolve path to module 'express-serve-static-core' import/no-unresolved // edit:
Minimal reproducible example here: |
The problem seems to come for types installed through http://definitelytyped.org/. |
@ThomasdenH can you try using https://www.npmjs.com/package/eslint-import-resolver-typescript as your resolver and see if it fixes? if it does, I think it may solve many TS-related issues. I just used it to solve some weird ones in my day job codebase edit: I think it won't help after all, based on import-js/eslint-import-resolver-typescript#17 + associated PR but it's an easy experiment |
@manuelbieh I think your case is a little different than OP. I see you're using the typescript resolver but it works fine for me... and it would be possible for the |
@benmosher , thanks the typescript resolver worked for me. Note for reference that you can have multiple import resolvers (I didn't want to turn off the webpack resolver so I hadn't tried the typescript one earlier). |
Sorry for the late reply! Unfortunately it doesn't fix the issue, but thanks for the suggestion. |
@ThomasdenH: yep, makes sense. I didn't fully understand the scenario when I originally suggested. |
I am having the same issue for an intl-type that is generated by DefinitelyTyped. Is there any solution or further ideas on how to fix it? |
For anyone maybe interested, you can try |
@benmosher It's just using npm package with github branch. |
I'm running into this issue as well. Imports from declarations are very common, so this is a real pain. It would be great to get a fix |
again, resolution is out of scope for this plugin. will close when @JounQin's PR is accepted or other similar fix is implemented by |
The way I understand it, its not possible for a resolver to solve this problem. Resolvers can only return a single file, but in this case of separate source and declaration files, the exports are distributed across 2 files. e.g. // file.d.ts
export type Fruit = {
color: string,
}; // file.js
export const tomato = {
color: 'red',
}; // index.ts
import { Fruit, tomato } from './file'; // <-- these exports do not come out of any one file |
@hedgepigdaniel You should add |
@benmosher Should this issue be closed in favor of eslint-import-resolver-ts? |
Make sure you have inside the
|
@benfletcher @ThomasdenH @ljharb @stekycz This issue can be closed definitely in favor of eslint-import-resolver-typescript@2.0.0. |
@JounQin which change in that new version addresses this issue? |
@hedgepigdaniel You can always read the CHANGELOG by yourself. |
@JounQin i've done so, and i have no idea which change addresses this issue. Could you clarify? |
@ljharb I was thinking we were in the same context here: import-js/eslint-import-resolver-typescript#20 (comment), didn't we? And also #1341 (comment) and #1341 (comment) |
Yes but those don't tell me which specific commits in the changelog address this issue :-) |
@ljharb Did you read https://github.com/alexgorbatchev/eslint-import-resolver-typescript/blob/master/CHANGELOG.md#features?
I made that PR first and accidentally found it could fix this issue already. I don't think that's my responsibility to clarify that this issue has been fixed by another third party package which has been released. |
Does that mean there is now a problem where if there is a declaration file, there is a false error when importing a value from the module that has the declarations? |
I guess that isn't a problem if you have types for all exported symbols |
@hedgepigdaniel Sorry my English is not so good enough for understanding what's your point? Do you have an example? Maybe I can understand what's your meaning now. Of course, |
// apple.js
export const color = 'red';
export const shape = 'round'; // apple.d.ts
export const color: string; // index.ts
// vv Error: shape is not defined in `apple.d.ts`!
import { shape } from './apple'; |
@hedgepigdaniel Yeah, but that is a bad practice and should never happen. |
@JounQin it's not about what's your responsibility; it's about being friendly and helpful :-) Thanks for pointing me to import-js/eslint-import-resolver-typescript@b11ede3. |
@ljharb Emm... I'm always friendly, but my pointed CHANGELOG and PR both target the same commit which fixed this issue. Maybe we both need to be more patient and find out the key point by ourselves? Cheers. |
…core" by following the discussion in import-js/eslint-plugin-import#1341
I think I have found a bug with
import/named
. I have created a repository that reproduces the issue.The line that gives problems is
It imports an interface defined in a
d.ts
file. The following warning is given:PR #1304 should solve importing types to typescript, but maybe this doesn't work for declaration files? Or is there something wrong with my configuration?
The text was updated successfully, but these errors were encountered: