Files
SnowLuma/.pnpm-store/v11/files/db/43918b53230ab20a23d16861c3fac6444121c21db370a50f2754f11788164f08dbf7a41c61e7b79f4f2ca2403589aab38f6f5d50d17acd24a02d40c0f27e2f
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

47 lines
2.3 KiB
Plaintext

import * as React from 'react';
type ContextProvider<ContextValueType extends object | null> = React.FC<ContextValueType & {
children: React.ReactNode;
}>;
interface UseAssertedContext<ContextValueType extends object | null> {
(consumerName: string): ContextValueType;
}
interface UseContext<ContextValueType extends object | null> {
(consumerName: string): ContextValueType;
(consumerName: string, options: {
optional: true;
}): ContextValueType | undefined;
}
declare function createContext<ContextValueType extends object | null>(rootComponentName: string): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>];
declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext: ContextValueType): readonly [ContextProvider<ContextValueType>, UseAssertedContext<ContextValueType>];
type Scope<C = any> = {
[scopeName: string]: React.Context<C>[];
} | undefined;
type ScopeHook = (scope: Scope) => {
[__scopeProp: string]: Scope;
};
interface CreateScope {
scopeName: string;
(): ScopeHook;
}
type ScopedContextProvider<ContextValueType extends object | null> = React.FC<ContextValueType & {
scope: Scope<ContextValueType>;
children: React.ReactNode;
}>;
interface UseScopedContext<ContextValueType extends object | null> {
(consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;
(consumerName: string, scope: Scope<ContextValueType | undefined>, options: {
optional?: true;
}): ContextValueType | undefined;
}
interface UseAssertedScopedContext<ContextValueType extends object | null> {
(consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;
}
interface CreateScopedContext {
<ContextValueType extends object | null>(rootComponentName: string): readonly [ScopedContextProvider<ContextValueType>, UseScopedContext<ContextValueType>];
<ContextValueType extends object | null>(rootComponentName: string, defaultContext: ContextValueType): readonly [ScopedContextProvider<ContextValueType>, UseAssertedScopedContext<ContextValueType>];
}
declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [CreateScopedContext, CreateScope];
export { type CreateScope, type Scope, createContext, createContextScope };