We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Let's Make a Generic Inference Algorithm - Ryan Cavanaugh, TypeScript Congress 2023
Discover how to create a generic inference algorithm that infers types in TypeScript, considering context, type variance, and more, with a focus on providing a good enough answer even in ambiguous cases.
- The goal is to create a generic inference algorithm that can infer types in TypeScript.
- The algorithm should consider the context and relate input types to output types.
- Type inference is not always about finding the correct answer, but rather the best answer that makes sense.
- The algorithm involves collecting candidates, prioritizing them, and choosing the best one.
- The best answer is often the one that contains all the other candidates.
- The algorithm should consider type variance and the relationship between input and output types.
- Type inference is not always perfect and may require additional information.
- The algorithm should be able to handle ambiguous cases and provide a good enough answer.
- The algorithm should also consider the motivating examples and the intended behavior of the code.
-
The use of
any
andunknown
types can be useful in certain situations. - Type inference is a complex process that requires consideration of many factors.
- The algorithm should be able to handle multiple type arguments and union types.
- The concept of “best” is subjective and may require additional information to determine.
- Type inference is not always about finding the most specific type, but rather the best type that makes sense.
- The algorithm should be able to handle cases where there are multiple candidates and no clear best answer.
- The algorithm should be able to consider the context and relate input types to output types.
- Type inference is a trade-off between correctness and practicality.
- The algorithm should be able to handle cases where there are no type annotations and inferring types is necessary.
- Type inference is a complex process that requires consideration of many factors and is not always perfect.
- The algorithm should be able to provide a good enough answer even in the face of ambiguity.
- The algorithm should be able to handle cases where there are multiple type arguments and union types.
-
The use of
box
andunbox
can be useful in certain situations. - Type inference is a complex process that requires consideration of many factors and is not always perfect.