镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Example in README cannot be compiled in TypeScript #243

Open

Description

@kenkoooo

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>;
});

Activity

  1. ryanbrainard commented on Jan 6, 2020

    @ryanbrainard
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions