Files
react-native/types/modules/Codegen.d.ts
T
Nick Gerleman 5d26ceaa23 Fixup TS Organization (#35169)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35169

This reorganizes typing structure a bit.

`Utilities.d.ts` was originally added for utilitiy types but I ended up leaving it a grab bag of types that didn't belong to any individual bit of code. Out of what is in it right now, `Insets` was actually public, and seems to have been imported.

We also run into files around the renderer which are [currently overwritten](https://github.com/facebook/react-native/commits/e286da25fc83324363486eb668806aca179f74b3/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts) by the React sync script.

Finally, all of the top-level imports of `Utilities` were auto-generated by VS Code, but fail in real apps. I think this is because our tsconfig sets a `baseUrl` to allow resolution from the types folder, so the tooling in the RN repo will use that, but it breaks in real apps that don't have that mapping.

This splits all these up into a couple separate directories that are hopefully easier to reason about, and removes `Omit` which has been a builtin type for quite some time (we were actually already using built-in `Omit`).

Changelog:
[General][Fixed] - Fixup TS Organization

Reviewed By: cipolleschi

Differential Revision: D40932319

fbshipit-source-id: 0b6e3e3eda603885b4dc01dcb9f5233aa546d128
2022-11-02 14:58:37 -07:00

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;
readonly paperComponentName?: string;
readonly paperComponentNameDeprecated?: string;
readonly excludedPlatforms?: ReadonlyArray<'iOS' | 'android'>;
}
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;
}