Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include output parameters in a function with Typescript?

Tags:

typescript

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#.

like image 681
user1941679 Avatar asked Jan 01 '13 23:01

user1941679


People also ask

How do you call a function with parameters in TypeScript?

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.

Can function have output parameters?

A stored procedures and functions may have input, output, and input/output parameters.

How do I create a return type function in TypeScript?

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.


1 Answers

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.

like image 72
Fenton Avatar answered Oct 17 '22 08:10

Fenton