Skip to content

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Dec 3, 2025

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 VisitorObjectBase it will infer the correct type, but if I write a random key, it'll just be inferred as ESTree.Node

Closes #14745

🤖 generated with help from Claude Opus 4.5

…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
@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-ast-tools Area - AST tools A-linter-plugins Area - Linter JS plugins C-bug Category - Bug labels Dec 3, 2025
Copy link
Contributor Author

camc314 commented Dec 3, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@camc314 camc314 marked this pull request as ready for review December 3, 2025 22:56
Copilot AI review requested due to automatic review settings December 3, 2025 22:56
@camc314
Copy link
Contributor Author

camc314 commented Dec 3, 2025

I'm going to write a test for this in a follow up after some more changes

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 VisitorObject from an interface to an intersection type
  • Split the visitor type into VisitorObjectBase (containing typed methods) and VisitorObject (intersection with index signature)
  • This allows specific keys to maintain their typed signatures while unknown keys use the generic (node: ESTree.Node) => void signature

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.

Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@camc314 camc314 marked this pull request as draft December 3, 2025 23:05
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 3, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 3, 2025

Merge activity

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: Error occurs when checking type in jsplugin definition function

3 participants