Perseus
    Preparing search index...

    Type Alias MakeWidgetMap<TRegistry>

    MakeWidgetMap: {
        [Property in keyof TRegistry as `${Property & string} ${number}`]: TRegistry[Property]
    }

    A utility type that constructs a widget map from a "registry interface". The keys of the registry should be the widget type (aka, "categorizer" or "radio", etc) and the value should be the option type stored in the value of the map.

    You can think of this as a type that generates another type. We use "registry interfaces" as a way to keep a set of widget types to their data type in several places in Perseus. This type then allows us to generate a map type that maps a widget id to its data type and keep strong typing by widget id.

    For example, given a fictitious registry such as this:

    interface DummyRegistry {
    categorizer: { categories: string[] };
    dropdown: { choices: string[] }:
    }

    If we create a DummyMap using this helper:

    type DummyMap = MakeWidgetMap<DummyRegistry>;
    

    We'll get a map that looks like this:

    type DummyMap = {
    `categorizer ${number}`: { categories: string[] };
    `dropdown ${number}`: { choices: string[] };
    }

    We use interfaces for the registries so that they can be extended in cases where the consuming app brings along their own widgets. Interfaces in TypeScript are always open (ie. you can extend them) whereas types aren't.

    Type Parameters

    • TRegistry