Say I have an object type like:
interface Thing {
a: number;
b: string;
}
Can Typescript automatically derive a function type from it?
function signatureDerivedFromThing(a: Thing["a"], b: Thing["b"]) {
// typeof signatureDerivedFromThing is ???<Thing>
};
Second question: Is the reverse possible?
I'm aware of the caveats of valid identifier names vs valid object keys, the unclear order of arguments, and the unspecified return type. I'm bridging the gap between value space and type space. But still. Is this possible?
Note that I don't want a function with 1 argument of type Thing, which would be rather straightforward with destructuring parameter assignment.
Rest parameters with value type ...rest: Thing[keyof Thing][]
is a step closer to my idea. But then I'm missing the number of arguments and their names.
Parameters<T>
seems almost enough for declaring object keys from a function signature, though labeled tuples does not seem quite enough to achieve that. I also didn't find any counterpart going from keys to function args.
I just cannot make the final leap from key name to argument name.