Skip to content

Commit 2f92c29

Browse files
Fix the types for isComment and isText (#6)
1 parent bbcdcfc commit 2f92c29

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

docs/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ If the passed value doesn't appear to be convertible to a VNode, the returned va
204204
### Type
205205

206206
```ts
207-
function isComment(vnode: any): vnode is (null | undefined | boolean | (VNode & { type: Comment }))
207+
function isComment(vnode: any): vnode is (null | undefined | boolean | (VNode & { type: typeof Comment }))
208208
```
209209

210210
### Description
@@ -346,7 +346,7 @@ Returns `true` if the passed value is a static VNode. Static VNodes are a specia
346346
### Type
347347

348348
```ts
349-
function isText(vnode: any): vnode is (string | number | (VNode & { type: Text }))
349+
function isText(vnode: any): vnode is (string | number | (VNode & { type: typeof Text }))
350350
```
351351

352352
### Description

src/vue-vnode-utils.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
cloneVNode,
3-
Comment,
3+
Comment as CommentVNode,
44
type Component,
55
type ComponentOptions,
66
createCommentVNode,
77
createTextVNode,
8-
Fragment,
8+
Fragment as FragmentVNode,
99
type FunctionalComponent,
1010
isVNode,
11-
Static,
12-
Text,
11+
Static as StaticVNode,
12+
Text as TextVNode,
1313
type VNode,
1414
type VNodeArrayChildren,
1515
type VNodeChild
@@ -18,7 +18,7 @@ import {
1818
// @ts-ignore
1919
const DEV = process.env.NODE_ENV !== 'production'
2020

21-
export const isComment = (vnode: unknown): vnode is (null | undefined | boolean | (VNode & { type: Comment })) => {
21+
export const isComment = (vnode: unknown): vnode is (null | undefined | boolean | (VNode & { type: typeof CommentVNode })) => {
2222
return getType(vnode) === 'comment'
2323
}
2424

@@ -30,7 +30,7 @@ export const isElement = (vnode: unknown): vnode is (VNode & { type: string }) =
3030
return getType(vnode) === 'element'
3131
}
3232

33-
export const isFragment = (vnode: unknown): vnode is ((VNode & { type: typeof Fragment }) | VNodeArrayChildren) => {
33+
export const isFragment = (vnode: unknown): vnode is ((VNode & { type: typeof FragmentVNode }) | VNodeArrayChildren) => {
3434
return getType(vnode) === 'fragment'
3535
}
3636

@@ -42,11 +42,11 @@ export const isStatefulComponent = (vnode: unknown): vnode is (VNode & { type: C
4242
return isComponent(vnode) && typeof vnode.type === 'object'
4343
}
4444

45-
export const isStatic = (vnode: unknown): vnode is (VNode & { type: typeof Static }) => {
45+
export const isStatic = (vnode: unknown): vnode is (VNode & { type: typeof StaticVNode }) => {
4646
return getType(vnode) === 'static'
4747
}
4848

49-
export const isText = (vnode: unknown): vnode is (string | number | (VNode & { type: Text })) => {
49+
export const isText = (vnode: unknown): vnode is (string | number | (VNode & { type: typeof TextVNode })) => {
5050
return getType(vnode) === 'text'
5151
}
5252

@@ -59,7 +59,7 @@ export const getText = (vnode: VNode | string | number): string | undefined => {
5959
return String(vnode)
6060
}
6161

62-
if (isVNode(vnode) && vnode.type === Text) {
62+
if (isVNode(vnode) && vnode.type === TextVNode) {
6363
return String(vnode.children)
6464
}
6565

@@ -119,13 +119,13 @@ export const getType = (vnode: unknown) => {
119119
const typeofType = typeof type
120120

121121
if (typeofType === 'symbol') {
122-
if (type === Fragment) {
122+
if (type === FragmentVNode) {
123123
return 'fragment'
124-
} else if (type === Text) {
124+
} else if (type === TextVNode) {
125125
return 'text'
126-
} else if (type === Comment) {
126+
} else if (type === CommentVNode) {
127127
return 'comment'
128-
} else if (type === Static) {
128+
} else if (type === StaticVNode) {
129129
return 'static'
130130
}
131131
} else if (typeofType === 'string') {

0 commit comments

Comments
 (0)