You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like a simple bug to fix - we fail to instantiate Settable<T, V> with T = Identity<V> when checking if the default (Identity<V>) is assignable to the constraint. PR is up at #31240
TypeScript Version: 3.4.4
Search Terms:
generic default type
Code
Expected behavior:
For certain types X and Y, the constraint "X extends Y" is either correct or incorrect and not both or neither.
Both interface Test 1 and type Test 2 contain the constraint “Identity extends Settable <Identity , V> for a type V” and no other constraints.
Therefore, both Test1 and Test2 should either meet or not meet the previous constraints.
Actual behavior:
Test1 is an error "Type 'Identity' does not satisfy the constraint 'Settable<T, V>'."
But, Test2 isn't an error.
Type constraint determination may change depending on whether the type is Generic Parameter Default.
Playground Link:
https://www.typescriptlang.org/play/#src=interface%20Settable%3CT%2C%20V%3E%20%7B%0D%0A%20%20%20%20set(value%3A%20V)%3A%20T%3B%0D%0A%7D%0D%0A%0D%0Aclass%20Identity%3CV%3E%20%7B%0D%0A%20%20%20%20readonly%20item%3A%20V%3B%0D%0A%20%20%20%20constructor(value%3A%20V)%20%7B%0D%0A%20%20%20%20%20%20%20%20this.item%20%3D%20value%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20set(value%3A%20V)%3A%20Identity%3CV%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20new%20Identity%3CV%3E(value)%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Ainterface%20Test1%3CV%2C%20T%20extends%20Settable%3CT%2C%20V%3E%20%3D%20Identity%3CV%3E%3E%20%7B%20%7D%3B%0D%0Alet%20test1%3A%20Test1%3Cnumber%3E%3B%0D%0A%0D%0Ainterface%20Test2Base%3CV%2C%20T%20extends%20Settable%3CT%2C%20V%3E%3E%20%7B%20%7D%3B%0D%0Atype%20Test2%3CV%3E%20%3D%20Test2Base%3CV%2C%20Identity%3CV%3E%3E%3B%0D%0Alet%20test2%3A%20Test2%3Cnumber%3E%3B
Related Issues:
The text was updated successfully, but these errors were encountered: