In a Typescript V2 repo I would like to write a function to produce a function backed property:
Normally for that you would return a FunctionsMap e.g: (See example)
import { FunctionsMap } from "@foundry/functions-api";
FunctionsMap<FlightAlertWorkshopTutorial, string>{
const map = new FunctionsMap<FlightAlertWorkshopTutorial, string>();
"@foundry/functions-api"
is not available in V2 Typecript repo’s so how would I produce a function backed property in a V2 repo? Thank you
Hi @emmanuel1, you can find a full type reference in our documentation here.
For your specific case, after importing FlightAlertWorkshopTutorial and generating your OSDK, you’ll want something like:
import { ObjectSpecifier } from "@osdk/client";
import { FlightAlertWorkshopTutorial } from "@ontology/sdk";
export default function myFunction(): Record<ObjectSpecifier<FlightAlertWorkshopTutorial>, string> {
...
}
Record is a built-in utility type in TypeScript (docs).
tdyck
3
See the docs for Typescript v2 types reference to see how to translate from a V1 Map to a V2 Record. Here is an example of what this Record will look like.
In your case, it will probably look like this:
function exampleFunction(): Record<ObjectSpecifier<FlightAlertWorkshopTutorial>, string> {
...
}
Oh that’s great, thank you