From d4d061d5d29ab77819f4b74676b0a6b31210f568 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Mon, 18 May 2020 05:54:38 +0200 Subject: [PATCH] uncomment asserts type annotations (will require typescript 3.7+) --- packages/babel-types/scripts/generators/typescript.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/babel-types/scripts/generators/typescript.js b/packages/babel-types/scripts/generators/typescript.js index ef460a73456e..850fac8f0643 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript.js @@ -127,9 +127,8 @@ for (const typeName of t.TYPES) { lines.push( `export function is${typeName}(node: object | null | undefined, opts?: object | null): ${result};`, - // TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations // eslint-disable-next-line max-len - `// export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${ + `export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${ result === "boolean" ? "node" : result };` ); @@ -137,8 +136,7 @@ for (const typeName of t.TYPES) { lines.push( // assert/ - // Commented out as this declaration requires TypeScript 3.7 (what do?) - `// export function assertNode(obj: any): asserts obj is Node`, + `export function assertNode(obj: any): asserts obj is Node`, // builders/ // eslint-disable-next-line max-len @@ -303,9 +301,8 @@ 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;` );