mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e088a4fe9c
Summary: This new type will be valid in Flow strict mode and can be used by native modules and components to replace `Object`, with the same semantics. This unblocks the migration of the most modules in the React Native package to Flow strict. Changelog: [Internal] Add UnsafeObject type compatible with Flow strict mode to use in native modules and components Reviewed By: RSNara Differential Revision: D25540631 fbshipit-source-id: 60b80bbc84a53aecc747e3a1799cdf551e1859cd
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @emails react_native
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const ESLintTester = require('./eslint-tester.js');
|
|
|
|
const rule = require('../react-native-modules');
|
|
|
|
const NATIVE_MODULES_DIR = __dirname;
|
|
|
|
const eslintTester = new ESLintTester();
|
|
|
|
const VALID_SPECS = [
|
|
{
|
|
code: `
|
|
import {TurboModuleRegistry, type TurboModule} from 'react-native';
|
|
import type {UnsafeObject} from 'react-native/Libraries/Types/CodegenTypes';
|
|
|
|
export interface Spec extends TurboModule {
|
|
func1(a: string): UnsafeObject,
|
|
}
|
|
export default TurboModuleRegistry.get<Spec>('XYZ');
|
|
`,
|
|
filename: `${NATIVE_MODULES_DIR}/NativeXYZ.js`,
|
|
},
|
|
];
|
|
|
|
const INVALID_SPECS = [
|
|
// Untyped NativeModule require
|
|
{
|
|
code: `
|
|
import {TurboModuleRegistry, type TurboModule} from 'react-native';
|
|
export interface Spec extends TurboModule {
|
|
func1(a: string): {||},
|
|
}
|
|
export default TurboModuleRegistry.get<Spec>('XYZ');
|
|
`,
|
|
filename: `${NATIVE_MODULES_DIR}/XYZ.js`,
|
|
errors: [
|
|
{
|
|
message: rule.errors.misnamedHasteModule('XYZ'),
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
eslintTester.run('../react-native-modules', rule, {
|
|
valid: VALID_SPECS,
|
|
invalid: INVALID_SPECS,
|
|
});
|