type Set1 = T extends any[] ? T : Pick> & { [SK1 in K1]-?: Required>; }[K1]; type Set2 = T extends any[] ? T : Pick> & { [SK1 in K1]-?: Required<{ [key in K1]: Set1; }>; }[K1]; declare function set(source: T, path: [K1], value: T[K1]): Set1; declare function set(source: T, path: [K1, K2], value: T[K1][K2]): Set2; interface State { a: { b: string; c: number; }; d: boolean; } const state: State = { a: { b: "", c: 0, }, d: false, }; const newState: State = set(state, ["a", 'b'], 'why'); // shouldn't be an error