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
The example below shows how one ought to be able to implement the opposite of the mapped type Partial<T>, which should removeundefined from the type of every single property in an interface.
You can never truly remove undefined from an optional property, but you remove optionality with mapped type modifiers (#21919), or use the Required type which is part of lib.d.ts now.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
The example below shows how one ought to be able to implement the opposite of the mapped type
Partial<T>
, which should removeundefined
from the type of every single property in an interface.TypeScript Version: 2.9.0-dev.201xxxxx
Search Terms:
exclude undefined mapped optional
Code
Expected behavior:
Actual behavior:
(notice that optionalString still contains
undefined
in its type definition)Playground Link:
https://www.typescriptlang.org/play/#src=type%20NeverUndefined%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BK%20in%20keyof%20T%5D%3A%20Exclude%3CT%5BK%5D%2C%20undefined%3E%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20MyInterface%20%7B%0D%0A%20%20%20%20undef%3A%20undefined%3B%0D%0A%20%20%20%20optionalString%3F%3A%20string%3B%0D%0A%20%20%20%20stringOrUndefined%3A%20string%20%7C%20undefined%3B%0D%0A%20%20%20%20definedString%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Atype%20NeverUndefinedMyInterface%20%3D%20NeverUndefined%3CMyInterface%3E%3B
Related Issues:
None
The text was updated successfully, but these errors were encountered: