I have a js function that outputs an array with 3 numbers. Could I define a type/interface/whatever that will treat the array as an object.
So that Somethig.GetVector().X transpiles into Something.GetVector()[0]
I have a js function that outputs an array with 3 numbers. Could I define a type/interface/whatever that will treat the array as an object.
So that Somethig.GetVector().X transpiles into Something.GetVector()[0]
Copyright © 2021 Jogjafile Inc.
No, TypeScript transpilation doesn't work that way.
You can define a TypeScript interface that extends an array:
However, the type information transpiles away to nothing - it's only used by TypeScript, not JavaScript.
Alternatively, you can define a function that converts the array into an object with friendly property names. It sounds like this is probably what you want for your use case: