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

Example in README cannot be compiled in TypeScript #243

Open
kenkoooo opened this issue Dec 20, 2019 · 1 comment
Open

Example in README cannot be compiled in TypeScript #243

kenkoooo opened this issue Dec 20, 2019 · 1 comment

Comments

@kenkoooo
Copy link

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>;
});
@ryanbrainard
Copy link
Contributor

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.

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

3 participants
@ryanbrainard @kenkoooo and others