Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

[TypeScript] Default global state types are lost. #50

Closed
efichot opened this issue Mar 19, 2019 · 2 comments
Closed

[TypeScript] Default global state types are lost. #50

efichot opened this issue Mar 19, 2019 · 2 comments
Assignees
Labels
feature A new feature is requested.
Milestone

Comments

@efichot
Copy link

efichot commented Mar 19, 2019

When I tried to type my global state inside my setGlobal(), when I retrieve my field with useGlobal() I lost the typing, ts say me my variable is of type 'any'.

@quisido
Copy link
Collaborator

quisido commented Mar 19, 2019

This is correct, unfortunately. There's no way for it to know. If you change the shape of the global state in another file, useGlobal can't know that or the new shape in order to tell you the type it is returning.

You can use useGlobal<Type>('property') to tell it the type.

I'm working on a complete rewrite of ReactN in TypeScript that should improve upon this system.. While types can't be inferred by useGlobal, they'll at least we inferred by Provider and supported by more helper functions than present.

@quisido quisido added feature A new feature is requested. support A user is requesting support. labels Mar 19, 2019
@quisido quisido self-assigned this Mar 19, 2019
@quisido quisido changed the title [Typescript] Type passed on global state are lose... [TypeScript] Default global state types are lost. Mar 27, 2019
@quisido quisido removed the support A user is requesting support. label Mar 27, 2019
@quisido quisido added this to the 2.0.0 milestone Mar 27, 2019
@quisido
Copy link
Collaborator

quisido commented Apr 14, 2019

This is fixed in the latest commit for 2.0, so closing this. :)

Thank you for your feedback!

@quisido quisido closed this as completed Apr 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature A new feature is requested.
Projects
None yet
Development

No branches or pull requests

2 participants