Skip to content

Commit

Permalink
Fix the types for isComment and isText (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
skirtles-code authored Jan 16, 2024
1 parent bbcdcfc commit 2f92c29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ If the passed value doesn't appear to be convertible to a VNode, the returned va
### Type

```ts
function isComment(vnode: any): vnode is (null | undefined | boolean | (VNode & { type: Comment }))
function isComment(vnode: any): vnode is (null | undefined | boolean | (VNode & { type: typeof Comment }))
```

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

```ts
function isText(vnode: any): vnode is (string | number | (VNode & { type: Text }))
function isText(vnode: any): vnode is (string | number | (VNode & { type: typeof Text }))
```

### Description
Expand Down
26 changes: 13 additions & 13 deletions src/vue-vnode-utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
cloneVNode,
Comment,
Comment as CommentVNode,
type Component,
type ComponentOptions,
createCommentVNode,
createTextVNode,
Fragment,
Fragment as FragmentVNode,
type FunctionalComponent,
isVNode,
Static,
Text,
Static as StaticVNode,
Text as TextVNode,
type VNode,
type VNodeArrayChildren,
type VNodeChild
Expand All @@ -18,7 +18,7 @@ import {
// @ts-ignore
const DEV = process.env.NODE_ENV !== 'production'

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

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

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

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

export const isStatic = (vnode: unknown): vnode is (VNode & { type: typeof Static }) => {
export const isStatic = (vnode: unknown): vnode is (VNode & { type: typeof StaticVNode }) => {
return getType(vnode) === 'static'
}

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

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

if (isVNode(vnode) && vnode.type === Text) {
if (isVNode(vnode) && vnode.type === TextVNode) {
return String(vnode.children)
}

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

if (typeofType === 'symbol') {
if (type === Fragment) {
if (type === FragmentVNode) {
return 'fragment'
} else if (type === Text) {
} else if (type === TextVNode) {
return 'text'
} else if (type === Comment) {
} else if (type === CommentVNode) {
return 'comment'
} else if (type === Static) {
} else if (type === StaticVNode) {
return 'static'
}
} else if (typeofType === 'string') {
Expand Down

0 comments on commit 2f92c29

Please sign in to comment.