-
-
Notifications
You must be signed in to change notification settings - Fork 2.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 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
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:
| Node extends TSESTree.Node, |
| public readonly node: 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.NodeWithParenttype union with all the constituents ofTSESTree.NodeexceptTSESTree.Program - Use that
TSESTree.NodeWithParentinDefinitionBaseand 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 |
π