You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible for a function to return a list of values? #3418
Largely I assume it isn't present in TypeScript, because it isn't present in JavaScript/EcmaScript and the intent of TypeScript is not to "break" JavaScript, but be able to emit valid JavaScript, which would be hard to do.
As a way of solving this in a "JavaScript way", ES6 is adding array destructuring assignment and TypeScript allows you to utilise this feature now.
functionx(){return[1,'dsdsq',45678.45];}let[a,b,c]=x();/* a = 1, b = 'dsdsq', c = 45678.45 */
TypeScript allows you to destructure arrays, even when targeting non-ES6.
Activity
zhongsp commentedon Jun 8, 2015
Maybe you could use tuple types:
kitsonk commentedon Jun 8, 2015
Largely I assume it isn't present in TypeScript, because it isn't present in JavaScript/EcmaScript and the intent of TypeScript is not to "break" JavaScript, but be able to emit valid JavaScript, which would be hard to do.
As a way of solving this in a "JavaScript way", ES6 is adding array destructuring assignment and TypeScript allows you to utilise this feature now.
TypeScript allows you to destructure arrays, even when targeting non-ES6.
RyanCavanaugh commentedon Jun 8, 2015
If you combine the comments so far, you'll end up at an ideal solution:
We can't change the existing JS syntax since the comma operator already has a different meaning here.
Vadorequest commentedon Jun 8, 2015
Thanks!
Le 8 juin 2015 18:32, "Ryan Cavanaugh" notifications@github.com a écrit :