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 have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Relevant Package
scope-manager
Playground Link
No response
Repro Code
See https://github.com/typescript-eslint/typescript-eslint/pull/11322/files#r2158282689
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/<rule-name>": ["error", ...<options>],
},
};
tsconfig
Expected Result
The types of nodes on scope-manager definitions are, to my knowledge, always nodes inside a source file. They're never the TSESTree.Program
themselves. Thus, they should always have a defined parent
property set to some parent node.
Actual Result
DefinitionBase
's node
property's type is from a type parameter constrained to TSESTree.Node
:
TSESTree.Node
includes TSESTree.Program
as a type constituent. Which is problematic because that's the only type of node that doesn't have a required parent
property.
We see in https://github.com/typescript-eslint/typescript-eslint/pull/11322/files#r2158282689 that some areas of code have to use a !
after node.parent
.
Additional Info
My initial instinct for solving this is to:
- Make a
TSESTree.NodeWithParent
type union with all the constituents ofTSESTree.Node
exceptTSESTree.Program
- Use that
TSESTree.NodeWithParent
inDefinitionBase
and other scope-manager types that can only ever be a node inside a file (i.e. with a parent)
Versions
package | version |
---|---|
@typescript-eslint/scope-manager |
8.34.1 |
@typescript-eslint/types |
8.34.1 |
💖