eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Enhance parser to understand TS's `declare module`

Open Brandon-Ritchie opened this issue 6 months ago • 8 comments

I was asked to open this issue here, instead of in eslint-import-resolver-typescript

After upgrading from eslint-import-resolver-typescript version 3.8.3 to 4.3.4 and I am getting errors that there are pretty much no exports availaboe from @uidotdev/usehooks.

The breaking change seems to be with version 3.9.0, when there was a migration between resolvers.

Here is a repository that shows the issue: https://github.com/Brandon-Ritchie/eslint-import-reproduction

Brandon-Ritchie avatar May 15 '25 17:05 Brandon-Ritchie

I'm pretty confused how this is an issue in the plugin, or how it could be fixed here - the resolver seems like the proper place to make any fixes related to TS resolution.

ljharb avatar May 15 '25 17:05 ljharb

@JounQin specifically suggest I open it here. I am also not entirely sure, unless I misunderstood the original comment: https://github.com/import-js/eslint-import-resolver-typescript/issues/448#issuecomment-2881855587

Brandon-Ritchie avatar May 15 '25 17:05 Brandon-Ritchie

I'm fine with closing here and re-opening there, if I misunderstood or he was incorrect.

Brandon-Ritchie avatar May 15 '25 17:05 Brandon-Ritchie

Actually, the more I think about this, I am agreeing with you entirely. Not sure how this wouldn't be a typescript resolver issue.

Closing the issue here.

Brandon-Ritchie avatar May 15 '25 17:05 Brandon-Ritchie

I don't think it makes sense to keep this open - parsing TypeScript is far outside of the responsibility of this plugin.

ljharb avatar May 15 '25 22:05 ljharb

I don't think it makes sense to keep this open - parsing TypeScript is far outside of the responsibility of this plugin.

I don't quite get it, we're parsing TypeScript to get the import/export info, it's just TypeScript could use another syntax declare module 'xx' which is totally valid, and I believe typescript-eslint already parsed it in AST, we can just get the correct module info.

JounQin avatar May 15 '25 22:05 JounQin

Hmm, I suppose there is a possibility of doing something in https://github.com/import-js/eslint-plugin-import/blob/da5f6ec13160cb288338db0c2a00c34b2d932f0d/utils/parse.js#L112 if the parser exposes sufficient info.

ljharb avatar May 15 '25 22:05 ljharb

Hmm, I suppose there is a possibility of doing something in

Sure, it's in the TSModuleBlock node, https://astexplorer.net/#/gist/b10951fd8455dabe0dd78d203b5cd512/b9d1b17a57adc0520e41c0ee262c34c14036a59a

We need to check the TSModuleDeclaration's id, and merge it into top level ExportNamedDeclarations.

JounQin avatar May 15 '25 23:05 JounQin