Fix ts estree type definition (#18438)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-12-07 16:50:35 +08:00
1 parent 576f952997
commit 1fa465679c
2 files changed
+16 -10

No files matched your search

+7 -7
View File
@@ -53,14 +53,14 @@ export type Node = ExtendNode<_Node>;
export type NodeMap = CreateNodeMap<Node>;
export type CommentMap = CreateNodeMap<Comment>;
type CreateNodeMap<InputNode extends Node | Comment> = {
[NodeType in InputNode["type"]]: Extract<InputNode, { type: NodeType }>;
type CreateNodeMap<Input extends Node | Comment> = {
[NodeType in Input["type"]]: Extract<Input, { type: NodeType }>;
};
type ExtendNode<InputNode> = InputNode extends _Node
type ExtendNode<Input> = Input extends _Node
? {
[Key in keyof InputNode]: ExtendNode<InputNode[Key]>;
[Key in keyof Input]: ExtendNode<Input[Key]>;
} & PrettierNodeAdditionalProperties
: InputNode extends readonly (_Node | any)[]
? ExtendNode<InputNode[number]>[]
: InputNode;
: Input extends readonly any[]
? ExtendNode<Input[number]>[]
: Input;
+9 -3
View File
@@ -2,9 +2,15 @@ import type { TSESTree } from "@typescript-eslint/typescript-estree";
type NodeOrComment = TSESTree.Node | TSESTree.Comment;
type ConvertTypeToString<Node extends NodeOrComment> = {
[Key in keyof Node]: Key extends "type" ? `${Node[Key]}` : Node[Key];
};
type ConvertTypeToString<Input> = Input extends NodeOrComment
? {
[Key in keyof Input]: Key extends "type"
? `${Input[Key]}`
: ConvertTypeToString<Input[Key]>;
}
: Input extends readonly any[]
? ConvertTypeToString<Input[number]>[]
: Input;
export type Node = ConvertTypeToString<TSESTree.Node>;
export type Comment = ConvertTypeToString<TSESTree.Comment>;