- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Description
TypeScript Version: 2.8.0-dev.20180216
Code
// Type-level filters to extract just the required or optional properties of a type// Defns from https://github.com/Microsoft/TypeScript/pull/21919#issuecomment-365491689typeOptionalPropNames<T>={[PinkeyofT]: undefinedextendsT[P] ? P : never}[keyofT];typeRequiredPropNames<T>={[PinkeyofT]: undefinedextendsT[P] ? never : P}[keyofT];typeOptionalProps<T>={[PinOptionalPropNames<T>]: T[P]};typeRequiredProps<T>={[PinRequiredPropNames<T>]: T[P]};// Let's extract just the optional property names in a typetypePropNames=OptionalPropNames<{req: string,opt?: number}>;// Names = "opt" | undefinedExpected behavior:PropNames = "opt"
Actual behavior:PropNames = "opt" | undefined. How did that undefined get in there?
Related Issues:
Noticed this while writing up #21988, but wasn't sure if the cause was related or not.
The RequiredProps and OptionalProps definitions come from #21919 (comment)
Metadata
Metadata
Assignees
Labels
No labels