Closed
Description
The README shows a declarative approach to writing hook-based react-async resolvers. However, if implemented with Typescript, the following error appears:
const Rejected: <T>(props: {
children?: AsyncChildren<T>;
persist?: boolean;
}) => JSX.Element
Type '{ children: (error: AsyncState<unknown>) => Element; state: AsyncState<StandardResp<CoinProfileResp>>; }' is not assignable to type 'IntrinsicAttributes & { children?: AsyncChildren<unknown>; persist?: boolean; }'.
Property 'state' does not exist on type 'IntrinsicAttributes & { children?: AsyncChildren<unknown>; persist?: boolean; }'.
Going into the definitions, it seems like state
isn't considered a prop that is passed through. The same goes for Pending
and Fufilled
components.
Metadata
Metadata
Assignees
Labels
No labels
Activity
eddiewang commentedon Aug 6, 2019
I did some more research. I had previously imported the component like so:
It seems like the components on the
Async
component are different than thehelper.js
components. However when I try to import them like in the docs:import { AsyncState, Fulfilled, Pending, Rejected } from 'react-async'
I got a TS error:
All three components (Fulfilled, Pending, Rejected) show as unavl in the typescript defs. Also, my app does not compile, with this error:
ghengeveld commentedon Aug 6, 2019
Hey, thanks for reporting. The problem is with a naming collision between the stand-alone
<Fulfilled>
(etc) versus<Async.Fulfilled>
. When importingFulfilled
there is ambiguity if that means the stand-alone version or the static member of Async.I have a fix for this ready, see #73
Care to review?
eddiewang commentedon Aug 6, 2019
Interesting. Your commit seems to resolve the TS error. Does TS by default export class methods as their base name? Confused as to why
Async.Fulfilled
gets exported toFulfilled
.I'll test the compilation in a few hours after a meeting. Thanks for the help!
eddiewang commentedon Aug 6, 2019
@ghengeveld here's the error I'm getting now:
No Typescript errors though. I'm using the
useFetch
hook returning anAsyncState<T>
and passing that in as the state.eddiewang commentedon Aug 6, 2019
@ghengeveld do you have a process for linking the libraries locally? Would be willing to add that into contributing.md.
yarn link
causes issues related tobabel/runtime
require resolve.babel/babel-loader#149
ghengeveld commentedon Aug 7, 2019
Yes, it uses
relative-deps
for the examples and Yarn workspaces with Lerna for the packages. The general process is to runyarn bootstrap
after the first install. Should be smooth sailing from there. Sometimes Yarn messes things up and you need to doyarn clean && yarn bootstrap
to clear it up.Don't use
yarn link
on examples, it won't work due to the way packages are built (with multiple compilation targets).eddiewang commentedon Aug 7, 2019
Thanks, I haven't heard of
relative-deps
before, so I'll try that. I need to start looking for Lerna and Yarn workspaces... both are seemingly getting very common these days!I have to say, using React Async has been an eye-opener for me. Async calls in React always felt like too much boilerplate, no matter which solution. This library is refreshingly flexible and seemingly future-proof! Kudos.
ghengeveld commentedon Aug 7, 2019
Thanks!
ghengeveld commentedon Aug 8, 2019
Hey, can you try out
react-async@8.0.0-alpha.0
? It's the pre-release version I just published containing the fix for this.It can also be installed as
react-async@next
.Fix ambiguous import on standalone helper components (fixes #72) (#73)
ghengeveld commentedon Aug 24, 2019
Released in v8.0.0
Thanks for helping out!