Conversation
…ith index signature Use intersection type instead of interface to avoid TypeScript strict mode errors when using defineRule with specific visitor methods like Program(). Closes #14745
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
I'm going to write a test for this in a follow up after some more changes |
There was a problem hiding this comment.
Pull request overview
This PR fixes a TypeScript strict mode error when using defineRule with specific visitor methods like Program(). The issue occurred because interfaces with index signatures cause all explicit properties to be type-checked against the index signature type in strict mode.
Key Changes:
- Changed oxlint's
VisitorObjectfrom an interface to an intersection type - Split the visitor type into
VisitorObjectBase(containing typed methods) andVisitorObject(intersection with index signature) - This allows specific keys to maintain their typed signatures while unknown keys use the generic
(node: ESTree.Node) => voidsignature
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tasks/ast_tools/src/generators/estree_visit.rs |
Updated the generator template for oxlint to create VisitorObjectBase and VisitorObject as an intersection type instead of a single interface |
apps/oxlint/src-js/generated/visitor.d.ts |
Generated TypeScript definition file with the new intersection type pattern that resolves strict mode errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
overlookmotel
left a comment
There was a problem hiding this comment.
Great!
Out of interest, would this still work if VisitorObjectBase was an interface? Or does it have to be a type too for this to work?
Merge activity
|
|
Closing for now, need to think about this more |

Use intersection type instead of interface to avoid TypeScript strict mode errors when using defineRule with specific visitor methods like Program().
This works as intersection types allow one type to overwrite another. So if i write a key that matches
VisitorObjectBaseit will infer the correct type, but if I write a random key, it'll just be inferred asESTree.NodeCloses #14745
🤖 generated with help from Claude Opus 4.5