-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
Design NotesNotes from our design meetingsNotes from our design meetings
Description
Rethinking Rest Destructuring on Generic Targets
function f1<T extends object>(obj: T, key: keyof T) {
const { [key]: removedValue, ...rest } = obj; // currently, `rest` is `Omit<T, keyof T>`
return rest;
}
rest
isOmit<T, keyof T>
, which is effectivelyobject
(or worse/weirder because it's likeRecord<never, ...>
).- Would want
rest
to bePartial<T>
instead ofOmit<T, keyof T>
so that it is still useful. - What patterns does this generalize to beyond something as specific as using
T
andkeyof T
? - Isn't the right thing to add a
K extends keyof T
instead?- Why didn't the original code do that?
- Probably just didn't think to add the type parameter?
- Could imagine that knowing this specific pattern would lead to us conjuring up a type parameter bounded to
keyof T
so that we could getOmit<T, (some specific keyof T)>
.
- Could imagine that knowing this specific pattern would lead to us conjuring up a type parameter bounded to
- We have a more precise approach, it's not the worst that we don't automatically model this specific code.
- Aside, why don't we have homomorphic
Omit
?
Change default --target
to esnext
esCURRENT
esnext
- Double-checking: are we okay with this idea?
- Breaks people without specified
target
. - Kind of weird because there is stuff that is "speculative" because it's only stage 3.
- Would be better if there was
eslatest
instead ofesnext
that was more stable.- Maybe
esstable
,escurrent
,esmodern
,esstandard
?
- Maybe
- Basically just refers to the latest stable version of ECMAScript.
- Probably would want the same for
lib
? - So the idea is that
eslatest
is just an alias for e.g.es202X
. - We feel like having either
esnext
or someeslatest
be the default makes sense because anything other than "oldest" is arbitrary. - Maybe we don't need a specific name here, but we just default to the latest stable version of ECMAScript.
- So this year it's
es2025
, next year it'ses2026
, etc.
- So this year it's
- This helps with the concern about code that uses modern features, but expects syntax that most runtimes don't support to be downleveled.
- By the way, do we need to change
--init
?- Probably - either omit the target or set it to the latest stable version.
Metadata
Metadata
Assignees
Labels
Design NotesNotes from our design meetingsNotes from our design meetings