Skip to content

feat: Generic Spec type support #275

@vanduyquang

Description

@vanduyquang

Hi, it seems like we don't support exporting a generic Spec type, currently Spec looks like this:

interface Spec {
    /** Root element key */
    root: string;
    /** Flat map of elements by key */
    elements: Record<string, UIElement>;
    /** Optional initial state to seed the state model.
     *  Components using statePath will read from / write to this state. */
    state?: Record<string, unknown>;
}

However, UIElement is a fully generic type:

interface UIElement<T extends string = string, P = Record<string, unknown>> {
    /** Component type from the catalog */
    type: T;
    /** Component props */
    props: P;
// ...

I wonder if we could add support for a Spec<T, P> type as well. For context, I want to pass Spec as a type to a React Hook Form form, but the type of elements should be limited to my own catalog only, and I have no way to that now without redefining Spec myself.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions