An example:
function doSomething(): { string, SomeClass } {
...
}
From playing around with the compiler it seems that it will accept any return value that is an object with any number of string
keys and SomeClass
values.
So something like this:
{
"key1": someClass1,
"key2": someClass2,
...
}
Is my understanding correct?
--Update--
It seems like the annotation I need is { [key: string]: SomeClass }
Nope - that function signature means 'this function will return an object that has the keys string
and SomeClass
, and any
values'. This means that this will compile fine:
function doSomething(): { string, SomeClass } {
return {
string: false,
SomeClass: 1
}
}
It's functionally equivalent to:
function doSomething(): { string: any, SomeClass: any }
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