Skip to content

Commit

Permalink
uncomment asserts type annotations (will require typescript 3.7+)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbodya committed May 18, 2020
1 parent b80ba09 commit d4d061d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/babel-types/scripts/generators/typescript.js
Expand Up @@ -127,18 +127,16 @@ 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
};`
);
}

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
Expand Down Expand Up @@ -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<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 d4d061d

Please sign in to comment.