haptic icon indicating copy to clipboard operation
haptic copied to clipboard

Missing explicit declaration for signal() return-type

Open mindplay-dk opened this issue 4 years ago • 0 comments

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 }>;

mindplay-dk avatar Aug 24 '21 18:08 mindplay-dk