Partial<T>[K] is not assignable to T[K] | undefined #47523
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Fix Available
A PR has been opened for this issue
Suggestion
An idea for TypeScript
Bug Report
...ok, I lied a little:
T
is a type variable / generic; butT
is concrete.So this report can be seen either as the lack of support of an expected rule (when
T
is concrete), or an inconsistency between the rules for generics and the rules for concretes.🔎 Search Terms
Searching for:
I found these potentially related issues:
undefined
fromPartial<T>[keyof T] | undefined
#45257 (comment)#45257 looks very similar. However, I think this report is a simpler case, and seems more directly related to the definition of
Partial<>
/ optional properties (?
), as something that adds| undefined
to the type of a property access expression. It also looks to me like a fix for this report would fix #45257 naturally.#31675 also looks related, but from the non-nullable perspective rather than the nullable one. The non-nullable inference rule also appears to be missing from both generic inference and concrete inference (e.g.,
NonNullable<Partial<T>[K]>
is not assignable forT[K]
for both genericT
and concreteT
), so at least there isn't an inconsistency there.🕗 Version & Regression Information
This changed between versions 3.3.3 and 3.5.1.
In 3.3.3,
Partial<T>[K]
was assignable toT[K] | undefined
for both genericT
and concreteT
.From 3.5.1, assignability is still allowed for generic
T
, but not for any particular concreteT
.⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Partial<T>[K]
is assignable toT[K] | undefined
whenT
is a genericPartial<T>[K]
is not assignable toT[K] | undefined
whenT
is concrete🙂 Expected behavior
Partial<T>[K]
toT[K] | undefined
should be consistent for both genericT
and concreteT
The text was updated successfully, but these errors were encountered: