My current situation involves the following types:
type Value = boolean | number | string
class Struct<T extends Value[] = Value[]> {
constructor(fmt: string) { }
pack(...args: T): Buffer { }
}
I am seeking guidance on how to replace <???>
with a list of the Value[]
used by each Struct
passed to the constructor in the snippet below:
class StructConcat<T extends Struct[]> {
constructor(...structs: T) { }
pack(...args_list: <???>) { }
}
// example:
const a: HeadStruct = new Struct<[number]>('<I')
const b: VectorStruct = new Struct<[number, number, number]>('<3f')
const concat = new StructConcat(a, b)
Ultimately, I want the StructConcat.pack
function to be limited to this form:
concat.pack([1], [2, 3, 4])
So far, the closest solution I have found is:
(T[number] extends Struct<infer K> ? K : never)[]
but it still outputs ([number] | [number, number, number])[]
instead of [[number], [number, number, number]]
as desired.
Is it possible within TypeScript's typing system to achieve this?