mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7858a2147f
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36345 `exactOptionalPropertyTypes` is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit `undefined`. This is not enabled when using `--strict`, and is stricter than Flow, leading to most of the typings having an `| undefined` unique to TypeScript (added with https://github.com/DefinitelyTyped/DefinitelyTyped/commit/694c663a9486dbe7794d5eb894a691ee9ded318a). We have not always followed this (I have myself previously assumed the two are equivalent). We can enforce that the convention is followed with a plugin `eslint-plugin-redundant-undefined`. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule `no-redundant-undefined`. Changelog: [General][Fixed] - Enforce compatibility with `exactOptionalPropertyTypes` Reviewed By: lunaleaps Differential Revision: D43700862 fbshipit-source-id: 996094762b28918177521a9471d868ba87f0f263
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
/**
|
|
* 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.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
declare module 'react-native/Libraries/Utilities/codegenNativeCommands' {
|
|
export interface Options<T extends string> {
|
|
readonly supportedCommands: ReadonlyArray<T>;
|
|
}
|
|
|
|
function codegenNativeCommands<T extends object>(
|
|
options: Options<keyof T extends string ? keyof T : never>,
|
|
): T;
|
|
|
|
export default codegenNativeCommands;
|
|
}
|
|
|
|
declare module 'react-native/Libraries/Utilities/codegenNativeComponent' {
|
|
import type {HostComponent} from 'react-native';
|
|
|
|
export interface Options {
|
|
readonly interfaceOnly?: boolean | undefined;
|
|
readonly paperComponentName?: string | undefined;
|
|
readonly paperComponentNameDeprecated?: string | undefined;
|
|
readonly excludedPlatforms?: ReadonlyArray<'iOS' | 'android'> | undefined;
|
|
}
|
|
|
|
export type NativeComponentType<T> = HostComponent<T>;
|
|
|
|
function codegenNativeComponent<Props extends object>(
|
|
componentName: string,
|
|
options?: Options,
|
|
): NativeComponentType<Props>;
|
|
|
|
export default codegenNativeComponent;
|
|
}
|
|
|
|
declare module 'react-native/Libraries/Types/CodegenTypes' {
|
|
import type {NativeSyntheticEvent} from 'react-native';
|
|
|
|
// Event types
|
|
// We're not using the PaperName, it is only used to codegen view config settings
|
|
|
|
export type BubblingEventHandler<
|
|
T,
|
|
PaperName extends string | never = never,
|
|
> = (event: NativeSyntheticEvent<T>) => void | Promise<void>;
|
|
export type DirectEventHandler<
|
|
T,
|
|
PaperName extends string | never = never,
|
|
> = (event: NativeSyntheticEvent<T>) => void | Promise<void>;
|
|
|
|
// Prop types
|
|
export type Double = number;
|
|
export type Float = number;
|
|
export type Int32 = number;
|
|
export type UnsafeObject = object;
|
|
|
|
type DefaultTypes = number | boolean | string | ReadonlyArray<string>;
|
|
// Default handling, ignore the unused value
|
|
// we're only using it for type checking
|
|
//
|
|
// TODO: (rickhanlonii) T44881457 If a default is provided, it should always be optional
|
|
// but that is currently not supported in the codegen since we require a default
|
|
|
|
export type WithDefault<
|
|
Type extends DefaultTypes,
|
|
Value extends Type | string | undefined | null,
|
|
> = Type | undefined | null;
|
|
}
|