# Getting started with TypeScript v2 functions TypeScript v2 allows users to take advantage of several key [improvements over TypeScript v1](../language-feature-support/index.md#typescript-v1-vs-typescript-v2), including a Node.js runtime and first-class OSDK support. Review the sections below to get started. ## Create a TypeScript v2 functions repository Navigate to a project of your choice and create a new code repository by selecting **+ New > Repository**. Select the TypeScript v2 functions template to initialize your repository. ![Create a TypeScript v2 function code repository.](../../../assets/853b1e196f3f1749c4c104241756358621aee00cf50a0ce21fb0ae03706b0de7.webp) Once the repository has been created, navigate to the `typescript-functions/src/functions/helloWorld.ts` file. Before you can import Ontology types into a function, add your object types and link types through the **Resource imports** sidebar, then generate and install the Ontology SDK. Refer to [Generate the Ontology SDK](../typescript-v2-migration/index.md#generate-the-ontology-sdk) for these steps. ## Write a function To write a new function, create a new file in the `typescript-functions/src/functions` directory of your repository and give it a descriptive name, for example, `helloWorld.ts`. Write your function using `export default` for Foundry to detect it. ```typescript tab="TypeScript v2" export default function helloWorld(): string { return "Hello World!"; } ``` You must satisfy the following conditions for your function to be published to Foundry: 1. Define your function in a `.ts` file in the `typescript-functions/src/functions` directory. In this directory, you can also group related functions in subdirectories. 2. The name of your file must match the name of your function. For a function called `myFunction` to be published, it must be defined in a file called `myFunction.ts` within the `typescript-functions/src/functions` directory. 3. The TypeScript function must be the default export of your file. 4. Your function's input and output types must follow the supported function types, as detailed in the [type reference](../types-reference/index.md). Your function's file path is used to uniquely identify the function that gets published from it, so changing the file path will result in a new function being published. ## Test in live preview To test your function in live preview, open the **Functions** helper and select **Live preview**. Choose your function and select **Run** to execute. Run your new function in the functions helper. ## Commit and publish a function Select **Commit** at the upper right corner of the window to commit your changes to the `master` branch of your repository. To view your function's checks, open the **Checks** tab at the top of the page. Here, after making a commit, you should see a running check. Select the check to view progress. After committing your work, you will see the **Tag version** option. This will publish all of the functions in your repository. ![The available tag options.](../../../assets/4d89b19a05620004ba26206ef862cd608a63e30ed89ccc997725774d77ed039f.webp) Select **Tag version** to tag a release off of the `master` branch. Set the tag name based on the extent of your changes, and then select **Tag and release**. Choose the version type to tag for the new release. To view the progress as your functions are tagged and released, select the **View** pop-up or navigate to the **Tags** tab. Once **Step 2: Release** is completed, select the published functions to view them in the function registry. :::callout{theme="warning"} Functions may not be immediately searchable by name in Workshop or the function registry while permissions propagate. ::: ![Both the tag and release checks passed, and the new function is published.](../../../assets/68894fe65c4ed2f25889486237f85ac7aa80e563fc72da1d41540cbac05ba59c.webp) ## Use a new function After the checks for your tag have passed, navigate back to the **Code** tab in **Code Repositories** and select the **Functions** helper. You should now be able to see your functions under the **Published** section. Select it and run the new function: ![Run the new function in the functions helper.](../../../assets/8b6e4f30f6a7e2bfbff697b187a1cc4b4844f294c5e8830c13957c32ad48edac.webp) ## Next steps After you create and publish a basic function, explore these capabilities: * **Ontology SDK:** To query or edit Ontology objects, first import the object and link types you need, then [generate and install the Ontology SDK](../typescript-v2-migration/index.md#generate-the-ontology-sdk). * **Ontology edits:** Learn how to [create, update, and delete objects](../typescript-v2-ontology-edits/index.md) in your functions. * **Staged writes \[Beta]:** For edit functions that need read-after-write guarantees or nested function calls, see [staged writes](../typescript-v2-staged-writes/index.md).