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
{{ message }}
Repository navigation
Regression: Partial properties became undefined instead of optional #37324
Consider that all messages are present, but may be undefined.
Type 'PartialMessages<{ $: string; welcome: string; }>' does not satisfy the constraint 'Messages'.
Property 'welcome' is incompatible with index signature.
Type 'string | undefined' is not assignable to type 'Message'.
Type 'undefined' is not assignable to type 'Message'.
Partial<T> seems to make property values optional rather than the keys. Even though it seems like a semantic difference, a non-existent property cannot be accessed by messages.<prop_name>, while a property with a potentially non-existent value may be accessed to give type | undefined. Quick fix for now would be something like:
Thank you Anders Hejlsberg (@ahejlsberg). So, if I understand, the best way to write what I expect is how suggested by Muthu Kumar (@MKRhere)?
I suggest to add this behavior (and the solution) in the « breaking change » list of 3.8…
Activity
RyanCavanaugh commentedon Mar 11, 2020
Anders Hejlsberg (@ahejlsberg) thoughts on this?
MKRhere commentedon Mar 11, 2020
Partial<T>seems to make property values optional rather than the keys. Even though it seems like a semantic difference, a non-existent property cannot be accessed bymessages.<prop_name>, while a property with a potentially non-existent value may be accessed to givetype | undefined. Quick fix for now would be something like:ahejlsberg commentedon Mar 12, 2020
This is working as intended and is an effect of #35143 (which was in the 3.8 release). Consider:
Clearly the two assignments should be checked the same and they are now. Note that neither assignment is an error when
--strictNullChecksis off.sveyret commentedon Mar 12, 2020
Thank you Anders Hejlsberg (@ahejlsberg). So, if I understand, the best way to write what I expect is how suggested by Muthu Kumar (@MKRhere)?
I suggest to add this behavior (and the solution) in the « breaking change » list of 3.8…
ahejlsberg commentedon Mar 12, 2020
Stéphane Veyret (@sveyret) I would probably change the declaration of
Messagestosveyret commentedon Mar 12, 2020
Yes, that's what I finally did. Thank you.
Shall I close the issue?