improve asserts type annotations (#12341)
This commit is contained in:
parent
a4e4aede14
commit
0f838be944
@ -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<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;`
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user