@knyt/luthier
Version:
A library for building standardized, type-safe native web components with full SSR and hydration support.
43 lines • 1.88 kB
TypeScript
import type { Reference } from "@knyt/artisan";
import type { SkipRenderSignal } from "./SkipRenderSignal";
/**
* A type representing a reference that holds a Promise, or may be undefined.
*
* @remarks
*
* This type is a union of two reference types to accommodate both cases:
* - a reference to a possibly `undefined` promise
* - a reference to a definitely defined promise
*
* This is necessary because TypeScript does not allow a single reference type
* to represent both cases within the `Reference` type.
*/
export type PromiseReference<T> = Reference.Readonly<Promise<T | typeof SkipRenderSignal> | undefined> | Reference.Readonly<Promise<T | typeof SkipRenderSignal>>;
export declare namespace PromiseReference {
/**
* The unwrapped type of a `PromiseReference`.
*
* @remarks
*
* If the reference holds a `Promise<U>` or `Promise<U> | undefined`,
* the unwrapped type is `U`. Otherwise, it is `never`.
*
* This type is a union of two conditional types to handle both cases.
* This is necessary because TypeScript does not allow a single conditional type
* to extract the inner type from both `Promise<U>` and `Promise<U> | undefined`.
*/
type Unwrapped<T> = T extends Reference.Readonly<Promise<infer U | typeof SkipRenderSignal>> ? U : T extends Reference.Readonly<Promise<infer U | typeof SkipRenderSignal> | undefined> ? U | undefined : never;
/**
* A tuple type representing multiple `PromiseReference` types.
*/
type Collection<T> = [...refs: PromiseReference<T>[]];
namespace Collection {
/**
* The unwrapped types of a tuple of `PromiseReference` types.
*/
type Unwrapped<T extends readonly unknown[]> = {
[K in keyof T]: PromiseReference.Unwrapped<T[K]>;
};
}
}
//# sourceMappingURL=PromiseReference.d.ts.map