'Remove all optional items from a Tuple type

Let say I want to turn a tuple with optional items like [1, 2, 3?, 4?] to an array containing only the required items -> [1, 2]

What i've come up with as shown below it to turn to never all optional items, and I'm stuck here.

type OnlyReq <L extends any []> = {
  [K in keyof L]-?: L [K] extends Required <L> [K]  ? L [K] : never
}

type Found = OnlyReq <[1, 2, 3?, 4?]> // [1, 2, never, never]

playground



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source