Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mindplay-dk opened this issue Aug 24, 2021 · 0 comments
Open

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

mindplay-dk opened this issue Aug 24, 2021 · 0 comments

Comments

@mindplay-dk
Copy link

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 }>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant