Getting started

Create a TypeScript Functions repository

Navigate to the project of your choice and create a new code repository by selecting + New > Repository. Select the TypeScript Functions template to initialize your repository.

Create a TypeScript Function code repository.

Once the repository is created, navigate to the functions-typescript/src/index.ts file.

Explore the repository

Your repository will have been initialized with an index.ts file containing a single function:

Copied!
1 2 3 4 5 6 export class MyFunctions { @Function() public myFunction(n: Integer): Integer { return n + 1; } }

This class contains a single Function called myFunction, which simply adds 1 to the integer provided to it.

Switch to the Checks tab at the top of the page, and you will see one check currently running. Select it, and wait until it succeeds.

Select the check to view progress.

Once the check is successful, select the Code tab again, then open the Functions helper. You will see myFunction in the results.

Open the Functions helper.

Select it, choose a value for n, and choose Run to execute the Function that was just published.

Run the Function in the Functions helper.

Add another Function

Now, let's add a more complex Function to this repository, test it, and publish it. Copy and paste the code below to the bottom of the MyFunctions class.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /** * Produces a range of integers between start and end, separated by the optional stepSize. * * @param start The start of the range * @param end The end of the range * @param stepSize The step size between numbers in the range. Defaults to 1. */ @Function() public range(start: Integer, end: Integer, stepSize: Integer = 1): Integer[] { const result = []; for (let current = start; current < end; current += stepSize) { result.push(current); } return result; }

Test in Live Preview

After you add the new Function, you can run it immediately in the Functions helper. Open the Functions helper and select Live Preview. Choose the range Function, enter input values, and select Run to run the code.

Run your new Function in the Functions helper.

Select Commit in the upper right to commit your changes onto the master branch of your repository.

Publish the Function

Once you commit your work, you will see the option to Tag version. This will publish all the Functions in your repository.

tags

Select Tag version to tag a release off the master branch. Set the tag name based on the extent of your changes, then choose 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 Branches tab in Code Repositories, and toggle to Tags and releases on the right side. Once Step 2: Release is completed, select the published functions to view them in the Functions registry.

Functions may not be immediately searchable by name in Workshop or the Functions library registry while permissions propagate.

Both the tag and release checks passed, and the new Function is published.

Use the 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 new range function under the Published section. Select it, and try running the new Function:

Run the new Function in the Functions helper.

Next steps

In this tutorial, you learned how to use Code Repositories to write, publish, and test a Function from a repository. Next, we recommend learning how to author Functions on Objects.