Type unification not working for nested types #36245
Labels
Bug
A bug in TypeScript
Domain: Variance Relationships
The issue relates to variance relationships between types
Milestone
TypeScript Version: 3.7.2, 3.6.3, 3.5.1 (but not 3.3.3)
Search Terms:
type unification
Explanation for the code:
We have a collection of different document types (think Firebase's Cloud Firestore if you're familiar with that). Each document type of which has a type associated with it which contains a few fields like the document type, the backend return type, etc. Then we have a number of functions in our store that take in one of these types and use the specific fields that they need. (Some functions will look at the
foo
field, some will not.) It's not at all uncommon for these to be passed through lots of wrapping functions until the last level pulls out the field that it needs.It is nice sometimes to be able to share code between two different (but similar) collection types. We can do if say their document type is the same (when two different endpoints return the same document). With recent versions of TypeScript we can only do that sharing if we expand the types at the place of definition.
Code
Expected behavior:
The program compiles.
Actual behavior:
It makes sense that if you want to check that
'WrappedJustFoo<Alpha>'
is assignable to type'WrappedJustFoo<Beta>'
you only check if'Alpha'
is assignable to type'Beta'
, but this isn't the only way they can be compatible.Related Issues: Nothing jumps out at me. #30134 maybe?
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: