type OriginalType = { key1: { sub1: string; sub2: string }; key2: { subA: string; subB: string }; }; type ValidKeys = keyof OriginalType; type ValidSubKeys = keyof OriginalType[K]; type FixedLengthArray = [T, ...T[]] & { length: L }; type EnforcedRecord = { [K in ValidKeys]: FixedLengthArray, L>; }; const createTable = ( cols: T, rows: EnforcedRecord ) => { return { cols, rows }; }; // Example usage: const cols = ["a", "b", "c"] as const; const table = createTable(cols, { key1: ['sub1', 'sub2', 'sub1', 'sub1'], // invalid because too long key2: ['subA', 'subB', 'sub1'], // invalid because bad key });