heroku / heroku/react-refetch

Typings problem with PromiseStateMapping/FunctionMapping

Open
#226 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
137
PR merge metrics
No merged PRs in 30d

Description

Hello! Thanks to those who contributed the TypeScript definitions, they're very useful. I did run into what looks like a problem with the `PromiseStateMapping` and `FunctionMapping` [definitions](https://github.com/heroku/react-refetch/blob/7951bbf0e87cb1b71a91e89c69c5da0f3603028f/src/index.d.ts#L77). They look like:

```typescript
type PromiseStateMapping<
TProps,
TProp extends keyof TProps
> = TProps[TProp] extends PromiseState
? string | Mapping
: never;

// Function
type FunctionMapping<
TProps,
TProp extends keyof TProps
> = TProps[TProp] extends ((...args: infer TArgs) => void)
? ((...args: TArgs) => PropsMap)
: never;
```
The two types

```typescript
TProps[TProp] extends PromiseState
```

and

```typescript
TProps[TProp] extends ((...args: infer TArgs) => void)
```
appear to need an `| undefined` appended to them. Without this, I get (at least with TypeScript 3.3.3) type errors with `connect()` whenever the refetch props of the component are declared as optional with `?`. But all refetch props need to be declared optional, since otherwise users of the component would have to pass them in. Does this sound right or am I missing something?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.