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
We create "substitution types" in conditional types - when writing T extends U ? TrueBranch : FalseBranch, we substitute T with something that's sort of equivalent to T & U in the TrueBranch.
Doing a "dumb" substitution.
When did we start supporting substitution types on primitives/literals?
Turns out it's relied upon quite a bit!
If you write "foo" extends keyof T ? ... : ..., you want to make a substitution type of "foo" and keyof T so that you can index into T with it in the true branch!
Example:
// Ensure the following real-world example that relies on substitution still workstypeExtractParameters<T>="parameters"extendskeyofT// The above allows "parameters" to index `T` since all later// instances are actually implicitly `"parameters" & keyof T`
? {
[KinkeyofT["parameters"]]: T["parameters"][K];}[keyofT["parameters"]]
: {};
You can figure that in contravariant positions, you don't actually want to produce the substitution type.
The issue is that not every use of a type implies strict variance. You could end up with some invariant and covariant and contravariant uses.
Should you create unions in contravariant positions?
Tracking Substitution Type Replacement
#43427
#43425
#43439
T extends U ? TrueBranch : FalseBranch
, we substituteT
with something that's sort of equivalent toT & U
in theTrueBranch
.Turns out it's relied upon quite a bit!
If you write
"foo" extends keyof T ? ... : ...
, you want to make a substitution type of"foo"
andkeyof T
so that you can index intoT
with it in the true branch!Example:
Fixing Excessive Stack Depth Issues
#43249
FlatArray
. Will experiment.Performance Depends on Declaration Order
#43437
const
that uses an interface before it's declared...it's somehow slower!Decorators Metadata Compat for SES
#43463
The text was updated successfully, but these errors were encountered: