From 0f838be944f1dd174be1da0fb2515b79a757c36d Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Mon, 16 Nov 2020 17:21:30 +0100 Subject: [PATCH] improve asserts type annotations (#12341) --- packages/babel-types/scripts/generators/typescript.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/babel-types/scripts/generators/typescript.js b/packages/babel-types/scripts/generators/typescript.js index 8ef2cb12ea01..210124d829df 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript.js @@ -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. @@ -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, allowPartial?: boolean): node is MemberExpression`, - // TypeScript 3.7: ": asserts n is T" // eslint-disable-next-line max-len - `export function validate(n: Node | null | undefined, key: K, value: T[K]): void`, + `export function validate(n: Node | null | undefined, key: K, value: T[K]): ${asserts( + "n is T" + )}`, `export function validate(n: Node, key: string, value: any): void;` );