kdojeteri
kdojeteri

Reputation: 805

Declare a polymorphic class that extends another polymorphic class

I'm writing a component in React that expects to receive a component, that owns a specific field onPropChange to be accessed via a ref, as a prop.

/* @flow */
import * as React from 'react';

type onPropChangeObject<Props> = {
    [key: $Keys<Props>]: (newValue: any) => void
}

declare class PropWatchableComponent<DefaultProps, Props: Object, State> 
    extends React.Component<DefaultProps, Props, State> 
{
    onPropChange?: onPropChangeObject<Props>;
}

But the type checking fails with multiple errors in the latest version of Flow (0.39.0) as seen here

8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ undefined. Did you forget to declare some incompatible instantiation of `DefaultProps`?. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ some incompatible instantiation of `DefaultProps`
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ undefined. Did you forget to declare some incompatible instantiation of `State`?. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ some incompatible instantiation of `State`
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                        ^ DefaultProps. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                        ^ undefined. Did you forget to declare DefaultProps?
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                                                     ^ State. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                                                     ^ undefined. Did you forget to declare State?

What's all this talk about undefined? I'm clearly declaring both DefaultProps and State as type parameters. What did I forget?

Upvotes: 1

Views: 373

Answers (1)

Related Questions