Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Relevant Package
utils
Playground Link
No response
Repro Code
constcreateRule=ESLintUtils.RuleCreator(name=>{construleName=parsePath(name).namereturn`${REPO_URL}/blob/@emotion/eslint-plugin@${version}/packages/eslint-plugin/docs/rules/${ruleName}.md`})// it isn't a problem with `createRule<never[], keyof typeof messages>({`createRule({name:__filename,meta:{docs:{description:'Ensure vanilla emotion is not used',recommended:false},messages:{vanillaEmotion:'Vanilla emotion should not be used'},schema:[],type:'problem'},defaultOptions:[],create(context){return{ImportDeclaration(node){if(node.source.value==='@emotion/css'){context.report({node:node.source,messageId:'vanillaEmotion'})}}}}})
ESLint Config
No response
tsconfig
No response
Expected Result
A definition file for a library utilizing this util should be generated just fine.
Actual Result
We get an error like this one:
TS2742: The inferred type of 'rules' cannot be named without a reference to '@typescript-eslint/utils/node_modules/@typescript-eslint/types/dist/generated/ast-spec'. This is likely not portable. A type annotation is necessary.
I've diagnosed this and the problem is that the finalRuleModule
contains a reference toTRuleListener
and its type contains references to types from another packages:
TRuleListener |
I've also figured out a workaround - we need to provide generic params explicitly, to disable the inference for the third generic param (TRuleListener
) and just use its default. The workaround in practice can be checked out here:https://github.com/emotion-js/emotion/pull/2761/files/79848d3a5ff7fa5338d31a27fb94951ea15071fa
I wonder though... why theTRuleListener
is a generic? Does it have to be referenced inRuleModule
? I would have assumed that a rule should be rather opaque to the consumer 🤔 (at least in relation to what kind of AST types does it process and stuff like that)
cc@JoshuaKGoldberg, funny enough that I've stumbled upon this issue just after this recent conversation on Twitter:https://twitter.com/JoshuaKGoldberg/status/1526969335717191692 😅
Additional Info
No response
Versions
package | version |
---|---|
@typescript-eslint/utils | 5.25.0 |
TypeScript | 4.5.5 |
ESLint | ^7.10.0 |