I've gotten pretty close already.
I have a set of tuples:
type Schema =
| ["link", string, string]
| ["recentFiles", "byPath", string, number]
| ["recentFiles", "byTime", number, string]
I created this type to iterate through all the prefixes:
type TuplePrefix<T extends unknown[]> = T extends [any, ...infer U]
? [] | [T[0]] | [T[0], ...TuplePrefix<U>]
: []
type Prefixes = TuplePrefix<Schema>
And now I want to filter this list based on whether it is prefixed by another tuple.
type Result1 = Extract<Schema, ["recentFiles"]> // ❌ never
type Result2 = Extract<Schema, {0: "recentFiles"}> // ✅ ["recentFiles", "byPath", string, number] | ["recentFiles", "byTime", number, string]
So it appears this extraction doesn't work for tuples.
I tried mapping from tuple to the object representation, but TypeScript won't have it.
type TupleToObject<T extends any[]> = {[K in keyof T]: T[K]}
Any ideas how to make this work?