question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncHookResult<T> is confusing & potentially buggy defined this way

See original GitHub issue

Feature Request

I would like to open a discussion about changing this

export type AsyncHookResult<T> = {
  loading: boolean,
  result: T | -1 | false | 'unknown',
}

Strongly typed languages like reasonml cannot just accept such things as “type1 or type2” (they provide variant for this usages). Since we are writing a zero-cost bindings (ie: just typing interface like flow & ts that doesn’t create extra js cost) https://github.com/reason-react-native/device-info it would be nice to have a reference that is more specific for each hooks & that doesn’t try to mix too many kind of result.

Why it is needed

I am updating reasonml zero cost bindings & struggle on that. I cannot write zero cost bindings with this current type if I blindly follow them. I think it could be a good idea to provide a better interface, more easy to type & maybe more intuitive.

Possible implementation

It seems some values are only used in some edge cases, so we could try to provide more types to be more specific? Should not be that hard to not rely on a single type for containing hooks results.

Code sample

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikehardycommented, Oct 4, 2020

Thanks for preening the issues list! Much appreciated, it needed it

1reaction
schiecommented, Oct 4, 2020

@mikehardy, can this be closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AsyncHookResult<T> is confusing & potentially buggy ...
I am updating reasonml zero cost bindings & struggle on that. I cannot write zero cost bindings with this current type if I...
Read more >
2021年08月_weixin_39970689的博客
AsyncHookResult <T> is confusing & potentially buggy defined this way. 2021-01-12 ... AsyncHookResult<T> is confusing & potentially buggy defined this way.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found