Skip to content

Commit

Permalink
improve asserts type annotations (#12341)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbodya committed Nov 16, 2020
1 parent a4e4aed commit 0f838be
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/babel-types/scripts/generators/typescript.js
Expand Up @@ -8,7 +8,7 @@ const toFunctionName = require("../utils/toFunctionName");
const ts3_7 = process.argv.includes("--ts3.7");

// TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations
const asserts = ts3_7 ? assertion => `asserts ${assertion}` : () => `boolean`;
const asserts = ts3_7 ? assertion => `asserts ${assertion}` : () => `void`;

let code = `// NOTE: This file is autogenerated. Do not modify.
// See packages/babel-types/scripts/generators/typescript.js for script used.
Expand Down Expand Up @@ -319,9 +319,10 @@ lines.push(
// the MemberExpression implication is incidental, but it follows from the implementation
// eslint-disable-next-line max-len
`export function matchesPattern(node: Node | null | undefined, match: string | ReadonlyArray<string>, allowPartial?: boolean): node is MemberExpression`,
// TypeScript 3.7: ": asserts n is T"
// eslint-disable-next-line max-len
`export function validate<T extends Node, K extends keyof T>(n: Node | null | undefined, key: K, value: T[K]): void`,
`export function validate<T extends Node, K extends keyof T>(n: Node | null | undefined, key: K, value: T[K]): ${asserts(
"n is T"
)}`,
`export function validate(n: Node, key: string, value: any): void;`
);

Expand Down

0 comments on commit 0f838be

Please sign in to comment.