Inspired by C#, I am looking to define the following:
type FunctionOutput<T> = T; // This is a basic implementation that needs improvement
type Result = {result: number};
function myFun(a: number, b: number, c: FunctionOutput<Result>)
{
c.result = a + b;
}
c: Result = {};
// What modification should be made in the FunctionOutput type to prompt an error in the following function call:
myFun(1, 2, c) // This should give Error: c is not of type FunctionOutput<Result>
// To ensure correct function call syntax, it would look like this:
myFun(1, 2, c as FunctionOutput<Result>);
console.log(c.result); // Outputs 3
My goal here is to clearly distinguish the output parameter in the function call and prevent users from mistakenly treating it as an input argument. The main question being:
How do I properly define the FunctionOutput
type?