ChatGPT failed to figure this out in maybe 16 attempts, with me feeding back the errors. I'm wondering if it's impossible.
Write a TypeScript function that prints its input parameter keys. The function has type parameters O and L, where O is any object and L is an array of keys of O. keys has type L, and the function can infer the type of L from keys, so that L need not be explicitly specified. Moreover, I need to be able to explicitly provide O in order to constrain the keys in keys. I'll be replacing the body of the function with code that uses L. The function does not take an instance of O.
interface Person { name: string; age: number; evil: boolean; }
function printKeys<O, L>(keys: L) { ... }
// example usage
printKeys<Person>(["name", "age"]); // typechecks
printKeys<Person>(["location"]); // type error