strictFunctionTypes restricts generic type

前端 未结 1 1706
心在旅途
心在旅途 2020-12-21 15:14

The problem seems to be specific to how strictFunctionTypes affects generic class type.

Here is a class that closely reproduces what happens and cannot be simplified

1条回答
  •  太阳男子
    2020-12-21 15:26

    This is at it's core an issue of variance. So first a variance primer:

    About variance

    Given a generic type Foo, and two related types Animal and Dog extends Animal. There are four possible relationships between Foo and Foo:

    1. Covariance - The arrow of inheritance points in the same direction for Foo and Foo as it does for Animal and Dog, so Foo is a sub type of Foo, which also means Foo is assignable to Foo
    type CoVariant = () => T
    declare var coAnimal: CoVariant
    declare var coDog: CoVariant
    coDog = coAnimal; // 

    0 讨论(0)
提交回复
热议问题