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
Seemed pretty complicated to come up with a new rules on higher order spread types so we waited on it.
Now that our type system has become pretty rich, we started wondering whether we could start to describe spread types in terms of conditional types and mapped types.
We can kind of do that, but there are certain caveats: our spread functionality tries to guess the "right" behavior to reflect the runtime.
We don't copy methods, we avoid set-only accessors, whatever.
Now if we want to do this in a higher-order sense (i.e. on generics), you need a way to select the keys that spread would actually copy those over.
So we thought about an own operator, but then you get into some unintuitive cases. For example, you'd think that for the following:
you'd get something assignable to a T. But no, instead you'd get something like a Spread<Own<T>, Own<T>> - which is not a T, and is not even an Own<T> without some extra work. So this is not great.
Up until now, Object.assign just returned intersections.
But spreads have almost identical semantics to Object.assign!
While it's not correct to return intersections, by and large it's been good enough.
So what we do now is that when you have a "zero-order" type (i.e. a non-generic type), we just do what we do today by constructing a new object type; but if you have a generic type, we'll stop and intersect with the current run of spreads.
So ...{ x: 100}, ...{ y: "hello" }, ...z where z has type T is { x: number, y: string } & T.
Generic object rest
The natural question arises: what about object rest.
Generic object spread and spread types (continued)
#10727
#21316 (comment)
#28234
Back in Add spread/rest higher-order types operator #10727, we speculated that we could have a new kind of type to describe the behavior of spread on generic types.
Seemed pretty complicated to come up with a new rules on higher order spread types so we waited on it.
Now that our type system has become pretty rich, we started wondering whether we could start to describe spread types in terms of conditional types and mapped types.
We can kind of do that, but there are certain caveats: our spread functionality tries to guess the "right" behavior to reflect the runtime.
We don't copy methods, we avoid set-only accessors, whatever.
Now if we want to do this in a higher-order sense (i.e. on generics), you need a way to select the keys that spread would actually copy those over.
So we thought about an
own
operator, but then you get into some unintuitive cases. For example, you'd think that for the following:you'd get something assignable to a
T
. But no, instead you'd get something like aSpread<Own<T>, Own<T>>
- which is not aT
, and is not even anOwn<T>
without some extra work. So this is not great.Up until now,
Object.assign
just returned intersections.Object.assign
!...{ x: 100}, ...{ y: "hello" }, ...z
wherez
has typeT
is{ x: number, y: string } & T
.Generic object rest
The natural question arises: what about object rest.
With Generic object rest variables and parameters #28312, if
obj
has typeT extends { foo: string }
, for the following code:now
f
returns the typePick<T, Exclude<keyof T, "foo">>
.There was some work that needed to be done with symbols.
What about the higher order components which are one of the most in-demand use-cases here?
Doesn't seem to "work" right
People might try to use
Pick<T, Exclude<keyof T, keyof U>>
and it still won't work.Sounds like we need subtraction types!
Exclude
.[[Discussion about subtraction types and negated types]]
Partial Type Argument Inference (revisited)
#26349
_
character._
is that it's a legitimate use-case_
but explicit type arguments are rare; so contextually reserving it is definitely overkill.Structurally identical-looking
Derived<T>
not assignable toBase<T>
#27984
Built-in base configs
#28147
The text was updated successfully, but these errors were encountered: