As of Typescript 4.0 with named tuples, I'm wondering if the following is possible:
declare const foo: <T extends string[], U extends memberOf T>(xs: T, x: U) => void
declare const ALL_OPTIONS: ['Alice', 'Bob']
foo(ALL_OPTIONS, 'Carl') // Error
foo(ALL_OPTIONS, 'Alice') // No Error
Basically I'm trying to constrain U
to an element of the tuple, something like memberOf
might exist in the same way that you could use keyOf
if T
was an Object.