Nish
Nish

Reputation: 547

Flowtype Polymorphism not working

I am trying to use Polymorphism for React components w/ inheritance, but I am seeing "This type is incompatible with some incompatible instantiation of V" error.

Here is the code:

// @flow

import React, { Component } from 'react'

type BaseProps = {
    name: string
}

type BaseState<T> = {
    error: string,
    value: ?T,
}

class Base<Props, V> extends Component<any, BaseProps & Props, BaseState<V>> {
    state = {
        error: '',
        value: null,
    }
    render() {
        return <div>this.props.name</div>
    }
}


type ExtendedProps = {
    foo: string,
}

class ExtendedBase extends Base<ExtendedProps, string> {
    render () {
        return <div>this.props.name</div>
    }
}

Link to Playground.

What am I doing wrong?

Upvotes: 2

Views: 223

Answers (1)

Nish
Nish

Reputation: 547

Answered on github

Had to defined types for state on Class.

Upvotes: 1

Related Questions