Полиморфизм Flowtype не работает

Я пытаюсь использовать полиморфизм для компонентов React с наследованием, но вижу ошибку «Этот тип несовместим с некоторыми несовместимыми экземплярами V».

Вот код:

// @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 .

Что я делаю не так?


person Nish    schedule 28.12.2016    source источник


Ответы (1)


Ответ на github

Пришлось определить типы для состояния в классе.

person Nish    schedule 28.12.2016