/** * Options for the `createContext` function. */ interface Options { /** * The default value for the context. * * @default null */ defaultValue?: value; /** * Function that is called when context has not been set but is trying to be gotten. * * @default () => {} */ onError?: (...args: unknown[]) => unknown; } /** * Return type of the `createContext` function. */ interface Context { /** * A unique symbol used to identify the context. */ key: symbol; /** * A function that retrieves the current value of the context. * If a `defaultValue` was provided and the context has not been set, it will return the `defaultValue`. * If an `onError` function is provided and the context has not been set, it will be called. * * @returns {GetValue} The value of the context */ get: () => GetValue; /** * A function that sets the value of the context. * * @param {SetValue} value - The value to set * @returns {SetValue} The value that was set */ set: (value: SetValue) => SetValue; /** * A function that checks if the context has been set. * * @returns {boolean} Whether the context has been set */ has: () => boolean; } /** * All the overloads for the `createContext` function. */ interface CreateContext { (options: { defaultValue: Value; onError: (...args: unknown[]) => unknown; }): Context; (options: { defaultValue: Value; }): Context; (options: { onError: (...args: unknown[]) => unknown; }): Context; (): Context; } /** * Creates a context object. * * @param {Options} options - Options * @return {Context} The created context object */ declare const createContext: CreateContext; export { createContext }; export type { Options, Context, CreateContext };