Skip to content

Typings problem with PromiseStateMapping/FunctionMapping #226

Open
@axon-q

Description

@axon-q

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. They look like:

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

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

The two types

TProps[TProp] extends PromiseState<infer TValue>

and

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?

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