Skip to content

fix: update TypeScript to v6 and tighten the return type of getParent#637

Merged
fasttime merged 11 commits intomainfrom
refactor/update-typescript-to-v6
Apr 28, 2026
Merged

fix: update TypeScript to v6 and tighten the return type of getParent#637
fasttime merged 11 commits intomainfrom
refactor/update-typescript-to-v6

Conversation

@lumirlumir
Copy link
Copy Markdown
Member

@lumirlumir lumirlumir commented Mar 25, 2026

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

Note

This PR follows the same strategy used in eslint/json#224 and eslint/json#230.

This PR updates TypeScript to v6.

The following two changes mainly affected us during the upgrade to TypeScript v6.

  • strict mode is now the default.

https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/#simple-default-changes

image
  • rootdir now defaults to .

https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/#rootdir-now-defaults-to-.

image

What changes did you make? (Give an overview)

I've tried to retain strict mode behavior as much as possible and only disabled it where it produced too many errors.

I've written more detailed descriptions as comments where necessary.

Related Issues

Refs: eslint/json#224, eslint/json#230

Is there anything you'd like reviewers to focus on?

N/A

@eslintbot eslintbot added this to Triage Mar 25, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Mar 25, 2026
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Mar 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions Bot added the Stale label Apr 6, 2026
@lumirlumir lumirlumir changed the title refactor: update TypeScript to v6 fix: update TypeScript to v6 and fix the return type of getParent. Apr 20, 2026
@lumirlumir lumirlumir changed the title fix: update TypeScript to v6 and fix the return type of getParent. fix: update TypeScript to v6 and fix the return type of getParent Apr 20, 2026
@lumirlumir lumirlumir changed the title fix: update TypeScript to v6 and fix the return type of getParent refactor: update TypeScript to v6 Apr 20, 2026
@lumirlumir lumirlumir changed the title refactor: update TypeScript to v6 fix: update TypeScript to v6 and fix the return type of getParent Apr 20, 2026
@lumirlumir lumirlumir removed the chore label Apr 20, 2026
@lumirlumir lumirlumir changed the title fix: update TypeScript to v6 and fix the return type of getParent fix: update TypeScript to v6 and tighten the return type of getParent Apr 21, 2026
Comment thread tests/types/tsconfig.json
Comment on lines +12 to +13
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To prevent the same issue as in eslint/json#88, I've also set the verbatimModuleSyntax and erasableSyntaxOnly options to true, as in the JSON type test.

https://github.com/eslint/json/blob/main/tests/types/tsconfig.json#L12-L13

Comment thread eslint.config-content.js
export default defineConfig([
globalIgnores(
["**/*.js", "**/.cjs", "**/.mjs"],
["**/*.js", "**/.cjs", "**/.mjs", "tests/fixtures/"],
Copy link
Copy Markdown
Member Author

@lumirlumir lumirlumir Apr 25, 2026

Choose a reason for hiding this comment

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

This addition prevents the warning that appears when I run npm run lint:

Image

Reference:

["**/examples/", "coverage/", "dist/", "src/build/", "tests/fixtures/"],

if (node.children) {
node.children.forEach(child => {
visit(child, node);
if ("children" in node) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the Markdown AST (Mdast), if a node has children they are always represented as an array (even when empty), so I think refactoring node.children to "children" in node is fine here.

* Returns the parent of the given node.
* @param {Node} node The node to get the parent of.
* @returns {Node|undefined} The parent of the node.
* @returns {Parent|undefined} The parent of the node.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is why the PR is marked as fix.

If the value is not undefined, the node is added to the private weakmap #parents only after the "children" in node check on line 331. In the Markdown AST (Mdast), a node with a children property always extends the Parent type, so using Parent instead of Node seems more accurate here.

@lumirlumir lumirlumir moved this from Implementing to Needs Triage in Triage Apr 25, 2026
@lumirlumir lumirlumir marked this pull request as ready for review April 25, 2026 13:34
@lumirlumir lumirlumir requested a review from fasttime April 25, 2026 13:34
@fasttime fasttime moved this from Needs Triage to Triaging in Triage Apr 27, 2026
@fasttime fasttime moved this from Triaging to Implementing in Triage Apr 27, 2026
Comment thread tsconfig.json Outdated
"rootDir": "./src",
"strictNullChecks": false,
"useUnknownInCatchVariables": false,
"types": ["mdast", "unist"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are these types packages included globally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I misunderstood how the types field works.

I've now realized how it works and updated it in 6399827.

@lumirlumir lumirlumir force-pushed the refactor/update-typescript-to-v6 branch from ff42108 to 6399827 Compare April 28, 2026 06:48
@lumirlumir lumirlumir requested a review from fasttime April 28, 2026 06:54
Copy link
Copy Markdown
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@fasttime fasttime merged commit 2573a54 into main Apr 28, 2026
34 checks passed
@fasttime fasttime deleted the refactor/update-typescript-to-v6 branch April 28, 2026 09:18
@github-project-automation github-project-automation Bot moved this from Implementing to Complete in Triage Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

4 participants