-
Couldn't load subscription status.
- Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
The example below shows how one ought to be able to implement the opposite of the mapped type Partial<T>, which should remove undefined from the type of every single property in an interface.
TypeScript Version: 2.9.0-dev.201xxxxx
Search Terms:
exclude undefined mapped optional
Code
type NeverUndefined<T> = {
[K in keyof T]: Exclude<T[K], undefined>;
}
interface MyInterface {
undef: undefined
optionalString?: string;
stringOrUndefined: string | undefined;
definedString: string;
}
type NeverUndefinedMyInterface = NeverUndefined<MyInterface>;Expected behavior:
// typeof NeverUndefinedMyInterface
interface NeverUndefinedMyInterface {
undef: never;
optionalString: string;
stringOrUndefined: string;
definedString: string;
}Actual behavior:
// typeof NeverUndefinedMyInterface
interface NeverUndefinedMyInterface {
undef: never;
optionalString: string | undefined;
stringOrUndefined: string;
definedString: string;
}(notice that optionalString still contains undefined in its type definition)
Related Issues:
None
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug