Skip to content

Commit 1953bbb

Browse files
committed
Add TextDescendant and Simplify types. Simplify NodeProps output.
1 parent 2b2ca32 commit 1953bbb

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/internal/createNodeProps.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {TextNode} from "../public/TextNode.js"
1111
import {NoIdFieldError} from "../public/NoIdFieldError.js"
1212

1313
import type {Descendant} from "./type/Descendant.js"
14+
import type {Simplify} from "./type/Simplify.js"
1415

1516
/**
1617
* @api private
@@ -38,16 +39,17 @@ interface ElementWithChildren {
3839
*
3940
* @api private
4041
*/
41-
type LeafNodeBase<T extends TextNode = TextNode> =
42+
type LeafNodeBase<T extends TextNode = TextNode> = Simplify<
4243
Replace<RenderLeafProps, LeafWithChildren & {
4344
leaf: T
4445
text: T
4546
}>
47+
>
4648

4749
/**
4850
* @api private
4951
*/
50-
type ElementNodeBase<T extends Node = Node> =
52+
type ElementNodeBase<T extends Node = Node> = Simplify<
5153
Replace<
5254
RenderElementProps,
5355

@@ -60,6 +62,7 @@ type ElementNodeBase<T extends Node = Node> =
6062
attributes: Omit<RenderElementProps["attributes"], "ref">
6163
}
6264
>
65+
>
6366

6467
/**
6568
* @api private
@@ -74,7 +77,7 @@ type NodeBaseProps<T extends Descendant> = T extends Node
7477
* @api private
7578
*/
7679
export type NodeProps<T extends Descendant> = Replace<NodeBaseProps<T>, {
77-
attributes: Replace<NodeBaseProps<T>["attributes"], PropsWithKey>
80+
attributes: Simplify<Replace<NodeBaseProps<T>["attributes"], PropsWithKey>>
7881
}>
7982

8083
/**
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import type {TextNode} from "../../public/TextNode.js"
2-
3-
import type {RichText} from "./RichText.js"
1+
import type {TextDescendant} from "./TextDescendant.js"
42
import type {Link} from "./Link.js"
53

6-
export type InlineDescendant = TextNode | RichText | Link
4+
export type InlineDescendant = TextDescendant | Link

src/internal/type/Link.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import type {TextNode} from "../../public/TextNode.js"
21
import type {Replace} from "../../public/Replace.js"
32
import type {Node} from "../../public/Node.js"
43

54
import {ELEMENT_LINK} from "../constants.js"
65

7-
import type {RichText} from "./RichText.js"
6+
import type {TextDescendant} from "./TextDescendant.js"
87

98
interface WithUrl {
109
url: string
1110
}
1211

1312
export type Link = Replace<Node<typeof ELEMENT_LINK>, {
14-
children: Array<TextNode | RichText>
13+
children: TextDescendant[]
1514
}> & WithUrl

src/internal/type/Simplify.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Simplify<T> = {[K in keyof T]: T[K]} & {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type {TextNode} from "../../public/TextNode.js"
2+
3+
import type {RichText} from "./RichText.js"
4+
import type {EmptyText} from "./EmptyText.js"
5+
6+
export type TextDescendant = EmptyText | RichText | TextNode

0 commit comments

Comments
 (0)