![Placeholder Image](https://cdn.prod.website-files.com/64b177d7207a0b5e76f37c0e/64b177d7207a0b5e76f37c11_placeholder.jpg)
![](https://cdn.prod.website-files.com/64b177d7207a0b5e76f37bc9/64b4d3882fdf5ab722de2568_typings.webp)
When using Typescript to build an app that uses Foundry’s ontology APIs, you’ll need interface definitions for your object types. While it doesn’t take very long to create these manually, we use a small script to automatically generate object type definitions by calling Foundry’s get object type endpoint.
![Screenshot of an object type interface definition printed to the console.](https://cdn.prod.website-files.com/64b177d7207a0b5e76f37bc9/64b6358299ef17f5808fe9a2_1*F-x-pnISgkGBUlJ0RycLJg.png)
Setup
This script is written in Typescript and uses Deno, a Typescript runtime. After cloning the repo and installing Deno on your machine, you’ll need to create some environment variables.
Generate a Foundry API token, and store it in an environment variable called <code>TOKEN</code>. Also store the hostname of your stack and the ontology rid for the relevant ontology. You can find the ontology rid in the Advanced pane of the Ontology Manager app:
Alternately, create a <code>.env</code> file and add your token there:
Usage
To use the script, run the following command. It will print out the interface definitions for each object type you supply. You can then copy the definitions wherever you need them. All properties except the primary key will be typed as optional. Properties will remain in the same order as received in the response from Foundry’s API.
Use the <code>-o</code> or <code>--objectTypes</code> option before the object types.
It will print the interface definitions:
Options
- If you want to extend a generic OntologyObject interface, add the <code>-e</code> or <code>--extendOntologyObject</code> option. This option is incompatible with the <code>-t</code> option and will be overridden by that option.
![Screenshot of an object type interface definition that extends an OntologyObject interface definition.](https://cdn.prod.website-files.com/64b177d7207a0b5e76f37bc9/64b636f099ef17f58091f8ee_1*rybGOvHUB2_D0nQ8FEygfg.png)
- If you want types instead of interfaces, add the <code>-t</code> or <code>--types</code> option.
- If you want the original object types included as comments, add the <code>-c</code> or <code>--commentOntologyType</code> option.
- If you want to type date and timestamp fields as strings instead of Date, add the <code>-d</code> or <code>--dateAsString</code> option.