/** * @description Extracts all non-undefined types from a union type T. * @template T The union type. */ type NonUndefined = T extends undefined ? never : T; // --- Usage Example --- type MixedValue = string | number | undefined | boolean; type OnlyDefined = NonUndefined; // Expected: string | number | boolean const val1: OnlyDefined = 'hello'; const val2: OnlyDefined = 123; const val3: OnlyDefined = true; // const val4: OnlyDefined = undefined; // Type error: Type 'undefined' is not assignable to type 'OnlyDefined'. type NullableString = string | null | undefined; type NonNullableAndNonUndefinedString = NonUndefined; // Expected: string | null // Combine with TypeScript's NonNullable for strict definition type StrictDefined = NonUndefined>; type StrictString = StrictDefined; // Expected: string