From 15b63bc89ea3e5e4814834b575471998247caa3e Mon Sep 17 00:00:00 2001 From: Matt Forster Date: Fri, 6 Sep 2019 12:54:03 -0600 Subject: [PATCH] fix(types): correct typescript function headers (#10404) Flow maybe types state; > Maybe types accept the provided type as well as null or undefined. So ?number would mean number, null, or undefined. So in this case, explicitly allow the type, null, or undefined in the typescript definition. Fixes #10403 --- packages/babel-types/scripts/generators/flow.js | 2 +- packages/babel-types/scripts/generators/typescript.js | 6 +++--- packages/babel-types/src/validators/isPlaceholderType.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/babel-types/scripts/generators/flow.js b/packages/babel-types/scripts/generators/flow.js index d82ced365c66..f3d8a85233fd 100644 --- a/packages/babel-types/scripts/generators/flow.js +++ b/packages/babel-types/scripts/generators/flow.js @@ -146,7 +146,7 @@ lines.push( `declare function isLet(node: BabelNode): boolean`, `declare function isNode(node: ?Object): boolean`, `declare function isNodesEquivalent(a: any, b: any): boolean`, - `declare function isPlaceholderType(placeholderType: ?string, targetType: string): boolean`, + `declare function isPlaceholderType(placeholderType: string, targetType: string): boolean`, `declare function isReferenced(node: BabelNode, parent: BabelNode, grandparent?: BabelNode): boolean`, `declare function isScope(node: BabelNode, parent: BabelNode): boolean`, `declare function isSpecifierDefault(specifier: BabelNodeModuleSpecifier): boolean`, diff --git a/packages/babel-types/scripts/generators/typescript.js b/packages/babel-types/scripts/generators/typescript.js index 35696923e1ae..6666a277d37e 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript.js @@ -153,13 +153,13 @@ lines.push( `export function isBlockScoped(node: Node): boolean`, `export function isImmutable(node: Node): boolean`, `export function isLet(node: Node): boolean`, - `export function isNode(node: ?object): boolean`, + `export function isNode(node: object | null | undefined): boolean`, `export function isNodesEquivalent(a: any, b: any): boolean`, - `export function isPlaceholderType(placeholderType: ?string, targetType: string): boolean`, + `export function isPlaceholderType(placeholderType: string, targetType: string): boolean`, `export function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean`, `export function isScope(node: Node, parent: Node): boolean`, `export function isSpecifierDefault(specifier: ModuleSpecifier): boolean`, - `export function isType(nodetype: ?string, targetType: string): boolean`, + `export function isType(nodetype: string | null | undefined, targetType: string): boolean`, `export function isValidES3Identifier(name: string): boolean`, `export function isValidES3Identifier(name: string): boolean`, `export function isValidIdentifier(name: string): boolean`, diff --git a/packages/babel-types/src/validators/isPlaceholderType.js b/packages/babel-types/src/validators/isPlaceholderType.js index fa775b7ed803..fac93b274532 100644 --- a/packages/babel-types/src/validators/isPlaceholderType.js +++ b/packages/babel-types/src/validators/isPlaceholderType.js @@ -5,7 +5,7 @@ import { PLACEHOLDERS_ALIAS } from "../definitions"; * Test if a `placeholderType` is a `targetType` or if `targetType` is an alias of `placeholderType`. */ export default function isPlaceholderType( - placeholderType: ?string, + placeholderType: string, targetType: string, ): boolean { if (placeholderType === targetType) return true;