In C#, it is possible to invoke a given method with named arguments:
myObject.SetSize(width: 100, height: 100);
They primarily seem to exist for catering to optional parameters, but... They also drastically improve readability of method call sites. It also protects you from incorrect parameter specification.
From what I have been able to gather, if I wish to benefit from 'declarative call sites' in TypeScript I'm best off using 'argument objects' based on a given interface.
interface SizeArguments {
width: number;
height: number;
}
export class MyClass {
setSize(args: SizeArguments) {
/* Set size... */
}
}
new MyClass().setSize({ width: 100, height: 100 });
Works for me! But that's still quite a lot of work for something so trivial in C#. Is this approach the best I can do right now? Or am I overseeing something fundamentally?