Skip to main content

FluidObject TypeAlias

This utility type take interface(s) that follow the FluidObject pattern, and produces a new type that can be used for inspection and discovery of those interfaces.

It is meant to be used with types that are known to implement the FluidObject pattern. A common way to specify a type implements the FluidObject pattern is to expose it as a FluidObject without a generic argument.

Signature

export type FluidObject<T = unknown> = {
[P in FluidObjectProviderKeys<T>]?: T[P];
};

Type Parameters

Parameter Default Description
T unknown

Example

For example, if we have an interface like the following:

interface IProvideFoo{
IFoo: IFoo
}
interface IFoo extends IProvideFoo{
foobar();
}

and a function that returns a FluidObject. You would do the following

const maybeFoo: FluidObject<IFoo> = getFluidObject();

Either IFoo or IProvideFoo are valid generic arguments. In both case maybeFoo will be of type {IFoo?: IFoo}. If IFoo is not undefined, then the FluidObject provides IFoo, and it can be used.

You can inspect multiple types via a intersection. For example: FluidObject<IFoo & IBar>