Skip to content

Missing explicit declaration for signal() return-type #19

@mindplay-dk

Description

@mindplay-dk

How do you define a type for a signal-based model?

The best pattern I could find thus far is something like this:

const Todo = (state: { title: string, done: boolean }) => signal(state);

type Todo = ReturnType<typeof Todo>;

So declare a constructor function, and then derive a type from it's return-type.

The disconnect here seems to be that, while signals can only be created as an object, only the derived individual properties of the returned type currently have an explicit generic type?

https://github.com/heyheyhello/haptic/blob/57f989a1ff1a0c62cfced149056c75646a3c8f63/src/state/index.ts#L274-L275

I don't actually need the constructor function, it's only there so I can derive a type - in this simple case, I'd prefer to have the static type only, without the run-time footprint.

Can we have a generic type for this? Something like:

type Todo = Signals<{ title: string, done: boolean }>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions