Installation
Install TypeSpec
Section titled “Install TypeSpec”TypeSpec can be used in two ways:
- Npm package for use with Node.js
- A standalone executable without any additional dependencies. Experimental
-
Install Node.js LTS
-
Install the TypeSpec CLI
Terminal window npm install -g @typespec/compiler
See package manager doc for more information on package managers.
Install the VS and VS Code extensions
Section titled “Install the VS and VS Code extensions”TypeSpec provides extensions for the following editors:
Create a new TypeSpec project
Section titled “Create a new TypeSpec project”-
Create a new TypeSpec project.
Terminal window tsp initThis will prompt you with a few questions. Pick the
Generic REST APItemplate, your project name, and make sure the@typespec/httpand@typespec/openapi3libraries are selected. -
Run a build to generate the OpenAPI specification output file.
Terminal window tsp compile .
- Invoke the command
>TypeSpec: Create TypeSpec Projectto create TypeSpec project, or clickCreate TypeSpec Projectbutton from the Primary Sidebar of Explorer. - Follow Quick Picks to select root folder of your project, pick the
Generic REST APItemplate, input your project name, make sure the@typespec/httpand@typespec/openapi3libraries are selected, then return to launch project scaffolding.

You should now have a basic TypeSpec project setup with a structure looking like this:
- main.tsp
- tspconfig.yaml
- package.json
Directorynode_modules/
- …
Directorytsp-output/
Directory@typespec/
Directoryopenapi3/
- openapi.yaml
- main.tsp: The entry point for your TypeSpec build. This file typically contains the main definitions for your models, services, and operations.
- tspconfig.yaml: Configuration file for the TypeSpec compiler, specifying options and settings for the build process.
- package.json: Contains metadata about the project, including dependencies, scripts, and other project-related information.
- node_modules/: Directory where npm installs the project’s dependencies.
- tsp-output/: Directory where the TypeSpec compiler outputs generated files.
- openapi.yaml: The generated OpenAPI specification file for your API, detailing the API’s endpoints, models, and operations. The output can vary based on the target format specified in the
tspconfig.yamlfile.
You can also run tsp compile . --watch to automatically compile changes on save.