Support simple dependent types based on conditional types or inedexed types #43876
Closed
5 tasks done
Labels
Suggestion
An idea for TypeScript
Too Complex
An issue which adding support for may be too complex for the value it adds
Suggestion
π Search Terms
dependent types, computed types, generics, conditional types, indexed types
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
I'd like to be able to declare a variable within a function whose type depends on the type of an argument to a generic function.
π Motivating Example
In this example,
repr
infoo
needs to be of typeRepr1
when foo's arg is of typeComp1
, and similarlyRepr2
forComp2
. Sorepr
's type is the dependent type I'd like to allow.Currently this doesn't compile because the assignment to
repr
is incompatible with its type, and the call tobar
is "no overload matches this call".π» Use Cases
This would simplify some of my code that currently has to use type guards to implement each case separately, where the only variation is the type of the
repr
variable, like this version (which works today):The text was updated successfully, but these errors were encountered: