@yandex/ymaps3-types
Version:
Types for ymaps3 maps library
52 lines (51 loc) • 3.28 kB
TypeScript
import type TReact from "react";
import type TReactDOM from "react-dom";
import { GenericEntity, Context, EntityConstructor, EntityProps } from "../imperative/Entities";
import { overrideKeyReactify } from "../imperative/wrappers";
type RefInstance<TEntity extends GenericEntity<unknown>> = React.MutableRefObject<TEntity | undefined>;
interface ReactParent {
entityRef: RefInstance<GenericEntity<unknown>>;
requestReposition(): void;
positionChild(entity: RefInstance<GenericEntity<unknown>>): number;
}
export declare let ReactParent: React.Context<[
ReactParent
] | undefined>;
export type Reactify = {
module: ReactifyModule;
entity: ReactifyEntity;
useDefault: <T>(value: T, dependencies?: unknown[]) => T;
};
export type CustomReactify<TEntity extends GenericEntity<unknown>, TResult> = (ctor: EntityConstructor<TEntity>, params: {
reactify: {
module: ReactifyModule;
entity<T extends EntityConstructor<GenericEntity<unknown>> = EntityConstructor<TEntity>>(...args: Parameters<InternalReactifyEntity<T>>): ReturnType<InternalReactifyEntity<T>>;
context: <TContext extends Context<unknown>>(context?: TContext) => TReact.Context<unknown>;
};
ReactParent: typeof ReactParent;
React: typeof TReact;
ReactDOM: typeof TReactDOM;
}) => TResult;
export type Overrided<TCtor extends EntityConstructor<GenericEntity<unknown>>, TReactResult> = {
[overrideKeyReactify]: CustomReactify<InstanceType<TCtor>, TReactResult>;
};
type InternalReactify<TEntity extends GenericEntity<unknown>> = (ctor: EntityConstructor<TEntity>, displayName?: string) => TReact.ForwardRefExoticComponent<TReact.PropsWithoutRef<TReact.PropsWithChildren<EntityProps<TEntity>>> & React.RefAttributes<TEntity | undefined>>;
type InternalReactifyEntity<TCtor extends EntityConstructor<GenericEntity<unknown>>> = (ctor: TCtor, displayName?: string) => TCtor extends Overrided<TCtor, infer TResult> ? TResult : ReturnType<InternalReactify<InstanceType<TCtor>>>;
export type ReactifyEntity = <TCtor extends EntityConstructor<GenericEntity<unknown>>>(...args: Parameters<InternalReactifyEntity<TCtor>>) => ReturnType<InternalReactifyEntity<TCtor>>;
export type ReactifiedEntity<TCtor extends EntityConstructor<GenericEntity<unknown>>> = ReturnType<InternalReactifyEntity<TCtor>>;
export interface ReactifyModule {
<TModule extends BaseModule = BaseModule>(module: TModule): ReactifiedModule<TModule>;
}
export type GetReactContext<TContext extends Context<unknown>> = (context?: TContext | undefined) => React.Context<unknown>;
export type ReactifiedModule<TModule extends BaseModule> = {
[Property in keyof TModule]: TModule[Property] extends EntityConstructor<GenericEntity<unknown>> ? ReturnType<InternalReactifyEntity<TModule[Property]>> : TModule[Property] extends Context<any> ? ReturnType<GetReactContext<TModule[Property]>> : TModule[Property];
};
export type BaseModule = Record<string | symbol, unknown> & {
__implReactifyOverride?: (reactify: Reactify) => object;
};
export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};
export type OverrideProps<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
export default function createReactify(React: typeof TReact, ReactDOM: typeof TReactDOM): Reactify;
export {};