react-native-codegen
Version:
⚛️ Code generation tools for React Native
46 lines (38 loc) • 830 B
Flow
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
;
import type {
NativeModuleTypeAnnotation,
Nullable,
} from '../../../CodegenSchema.js';
function unwrapNullable<+T: NativeModuleTypeAnnotation>(
x: Nullable<T>,
): [T, boolean] {
if (x.type === 'NullableTypeAnnotation') {
return [x.typeAnnotation, true];
}
return [x, false];
}
function wrapNullable<+T: NativeModuleTypeAnnotation>(
nullable: boolean,
typeAnnotation: T,
): Nullable<T> {
if (!nullable) {
return typeAnnotation;
}
return {
type: 'NullableTypeAnnotation',
typeAnnotation,
};
}
module.exports = {
unwrapNullable,
wrapNullable,
};