From a1ec0c6f2f8c9eca21054d014a38d3295f2bf135 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 20 Oct 2025 22:06:24 +0800 Subject: [PATCH] Fix type support for readonly arrays --- index.test-d.ts | 14 ++++++++++++++ lib/index.js | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index 48dbd93..c831675 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -204,6 +204,20 @@ visit(sampleTree, 'definition', function (node) { }) }) +visit(sampleTree, ['definition'], function (node) { + visit(node, function (node, _, parent) { + expectNotType(node) + expectNotType(parent) + }) +}) + +visit(sampleTree, ['definition'] as const, function (node) { + visit(node, function (node, _, parent) { + expectType(node) + expectType(parent) + }) +}) + function isHeading(node: Node): node is Heading { return node ? node.type === 'heading' : false } diff --git a/lib/index.js b/lib/index.js index 0d521ed..f4e61b2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -51,8 +51,8 @@ /** * @typedef {( - * Check extends Array - * ? MatchesOne + * Check extends ReadonlyArray + * ? MatchesOne * : MatchesOne * )} Matches * Check whether a node matches a check in the type system.