react-refetch icon indicating copy to clipboard operation
react-refetch copied to clipboard

Example in README cannot be compiled in TypeScript

Open kenkoooo opened this issue 6 years ago • 1 comments

Hi, I tried to compile the following example in 4.0.0-0 in TypeScript, which is in README, but I couldn't compile it.

import { connect, PromiseState } from "react-refetch";

interface Props {
  fooFetch: PromiseState<{}>;
  barFetch: PromiseState<{}>;
}

export default connect<{}, Props>(() => ({
  fooFetch: {
    url: `/foos/1`,
    andThen: foo => ({
      barFetch: `/bar-for-foos-by-id/1`
    })
  }
}))(() => {
  return <a>a</a>;
});

I fixed it like the following it can be compiled.

import { connect, PromiseState } from "react-refetch";

interface Props {
  fooFetch: PromiseState<{}>;
  barFetch: PromiseState<{}>;
}

export default connect<{}, Props>(() => ({
  fooFetch: {
    url: `/foos/1`,
    andThen: foo => ({
      fooFetch: { value: foo },
      barFetch: `/bar-for-foos-by-id/1`
    })
  },
  barFetch: { value: null }
}))(() => {
  return <a>a</a>;
});

kenkoooo avatar Dec 20 '19 12:12 kenkoooo

I thought I'd be able to fix this by making barFetch optional (i.e. barFetch?: PromiseState<{}>, but that did not work. I looks like your fix is the way to go for now, but we should either update the TypeScript defs and/or the readme.

ryanbrainard avatar Jan 06 '20 03:01 ryanbrainard