Is it possible to include output parameters in a function with TypeScript? Something like Func1(string val1, int out k1, int out k2)
in C#.
A Function is a block of code that you can use multiple times in an application. It can require one or more parameters. A list of parameters in parentheses, and a block of code in braces. To call a function, you code the function name followed by the function's parameters or arguments in parentheses.
A stored procedures and functions may have input, output, and input/output parameters.
To define the return type for the function, we have to use the ':' symbol just after the parameter of the function and before the body of the function in TypeScript. The function body's return value should match with the function return type; otherwise, we will have a compile-time error in our code.
Not currently.
You can return an object that can contain more than one property.
return { k1: 5, k2: 99 };
You can combine this with destructuring so the intermediate object becomes invisible...
function myFunction() { return { k1: 5, k2: 99 }; } const { k1, k2 } = myFunction(); console.log(k1); console.log(k2);
You could also achieve the same with a tuple, but this is pretty readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With