Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Apr 6, 2023
1 parent 680f69f commit d4a0ccc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/babel-types/scripts/generators/validators.js
Expand Up @@ -48,7 +48,7 @@ function addIsHelper(type, aliasKeys, deprecated) {

return `export function is${type}(${
BABEL8
? `node: t.Node | null | undefined, opts?: Partial<t.${type}> | null`
? `node: t.Node | null | undefined, opts?: Opts<t.${type}> | null`
: "node: object | null | undefined, opts?: object | null"
}): ${result} {
${deprecated || ""}
Expand Down Expand Up @@ -80,6 +80,14 @@ export default function generateValidators() {
import shallowEqual from "../../utils/shallowEqual";
import type * as t from "../..";
import deprecationWarning from "../../utils/deprecationWarning";
\n
type Opts<Object> = Partial<{
[Prop in keyof Object]: Object[Prop] extends t.Node
? t.Node | Object[Prop]
: Object[Prop] extends t.Node[]
? t.Node[] | Object[Prop]
: Object[Prop];
}>;
\n`;

Object.keys(VISITOR_KEYS).forEach(type => {
Expand Down Expand Up @@ -109,7 +117,7 @@ ${addIsHelper(type, null, `deprecationWarning("is${type}", "is${newType}")`)}`;
*/
export function is${type}(${
BABEL8
? `node: t.Node | null | undefined, opts?: Partial<t.${type}> | null`
? `node: t.Node | null | undefined, opts?: Opts<t.${type}> | null`
: "node: object | null | undefined, opts?: object | null"
}): node is t.${newType} {
deprecationWarning("is${type}", "is${newType}");
Expand Down

0 comments on commit d4a0ccc

Please sign in to comment.