Adam
Adam

Reputation: 3518

Flow type Generic types

I am trying to make a configurable type as follows:

import * as React from 'react';

type Identity<T: {}> = {
    data: {
        refetch: void => void,
        T: {}
    }
};

({ data }: Identity<{foo: string }>) => <div>{data.foo}</div>;

But I am getting:

Cannot get data.foo because property foo is missing in object type [1].

Am I missing something obvious? This is the shape of graphql hoc return data.

Thank you

Try Flow

Upvotes: 1

Views: 80

Answers (1)

Evert
Evert

Reputation: 99816

Did you mean:

type RefetchObj = {
    refetch: void => void,
}
type Identity<T: {}> = {
    data: T & RefetchObj
};

Upvotes: 2

Related Questions