---
sourceDocument: Australia Build or modify applications
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/application-development

 Release :

    - australia

ft:locale :

    - pt-BR

ft:publication_title :

    - Australia Build or modify applications

ft:clusterId :

    - cadev

bundleId :

    - cadev

workflow :

    - Development, Data, and Analytics


---

# Using TypeScript in JavaScript modules

# Using TypeScript in JavaScript modules with the ServiceNow SDK {#ariaid-title1}

* Versão de lançamento: Australia
* 
* Atualizado 12 de mar. de 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 min. de leitura

Use TypeScript when creating JavaScript modules with the ServiceNow SDK.

TypeScript uses static typing and type annotations to support developers catching errors earlier while writing code in Visual Studio Code.

For general information about using TypeScript, see the [TypeScript Documentation](https://www.typescriptlang.org/docs/) on the typescriptlang.org website.

## Use TypeScript in JavaScript modules {#ariaid-title2}

Use TypeScript in JavaScript modules by adding support for TypeScript in your application.

### Antes de Iniciar

Install TypeScript version 4.8.4 or later. For installation instructions, see [Download TypeScript](https://www.typescriptlang.org/download) on the typescriptlang.org website.

Role required: admin

### Por Que e Quando Desempenhar Esta Tarefa

Follow this procedure to update existing applications that weren't created using a TypeScript template to use TypeScript in modules if you're using ServiceNow SDK version 2.2.9 or earlier. Beginning with the ServiceNow SDK version 3.0, applications support using TypeScript in JavaScript modules by default using default compiler options. To use a tsconfig.json file with custom options for
transpiling TypeScript into JavaScript during the build process, configure the `tsconfigPath` parameter in the now.config.json file. If you want to use a custom transpilation step before
building the application, configure the `modulePaths` parameter in the now.config.json file.

With the ServiceNow SDK version 2.0.1 or later, you can configure applications to use TypeScript in JavaScript modules by default with the `template` parameter on the `now-sdk create`
and `now-sdk convert` commands. For more information, see [ServiceNow SDK CLI](https://servicenow-prod.fluidtopics.net/PRE3GTgYc~ImvC7_7y2WzA#servicenow-sdk-cli-commands "Use the ServiceNow SDK command-line interface (CLI) to manage changes between a local application and the application on an instance."). Follow this procedure to update existing applications to use TypeScript in modules.

### Procedimento

1. In Visual Studio Code, open your scoped application directory.
2. Open the application's package.json file and in the `devDependencies` object, add the TypeScript package and versionmake the following changes.  

       "devDependencies": {
           "typescript": "<version>",
           "@servicenow/sdk": "2.0.0",
           "@servicenow/glide": "26.0.1",
           "eslint": "8.50.0",
           "@servicenow/eslint-plugin-sdk-app-plugin": "2.0.0"
         }

   1. In the `devDependencies` object, add the TypeScript package and version.  

          "devDependencies": {
              "typescript": "<version>",
              "@servicenow/sdk": "2.0.0",
              "@servicenow/glide": "26.0.1",
              "eslint": "8.50.0",
              "@servicenow/eslint-plugin-sdk-app-plugin": "2.0.0"
            }

   2. In the `scripts` object, update the build script to compile TypeScript (.ts) modules to JavaScript (.js) for use on the instance.  

          {
              "scripts": {
                  "build": "tsc -b && now-sdk build",
              }
          }

   {#use-typescript-javascript-modules__substeps_ct4_r4v_szb}
3. In your application's src/serverbase directory, add a `tsconfig.json` file that defines the options for compiling the application.  

       {
           "compilerOptions": {
               "rootDir": "src/server",
               "outDir": "dist/server",
               "module": "nodenext",
               "target": "es2021",
               "moduleResolution": "nodenext",
           },
           "include": ["src/**/*.ts"],
           "exclude": ["node_modules", "src/fluent/**"],
           "references": []
       }

       {
           "compilerOptions": {
               "rootDir": "./",
               "outDir": "../../dist/server",
               "module": "es2022",
               "target": "es2022",
               "moduleResolution": "bundler",
               "allowJs": true,
               "declaration": false,
               "sourceMap": false,
               "skipLibCheck": true,
               "allowImportingTsExtensions": true,
               "noEmit": true
           },
           "include": [
               "./**/*.ts",
               "../../@types/**/*.modules.d.ts"
           ],
           "exclude": [
               "**/*.now.ts"
           ]
       }

4. In the application's now.config.json file, set the `tsconfigPath``modulePaths` parameter to the location of the `tsconfig.json` for JavaScript modules. map the TypeScript source files to the output modules based on your `tsconfig.json`.  

       {
         "scope": "x_snc_example_app",
         "scopeId": "2f8400eb07426110f736e28f69d3017a",   
         "name": "ExampleApp",
         "tsconfigPath": "./src/server/tsconfig.json"
         "modulePaths": {
             "src/server/*.ts": "dist/server/*.js"
          }
       }

5. In the src/server directory, add at least one .ts file to contain module code.  
   For information about creating modules, see [Create and use JavaScript modules in applications with the ServiceNow SDK](https://servicenow-prod.fluidtopics.net/yeUPdaCTbIDhv4Q7hPRTnw "Optimize your codebase by defining reusable code blocks with JavaScript modules and the ServiceNow SDK.").
6. Compile TypeScript files into JavaScript modules and build your application.
   1. From your application directory, open a command-line tool on your system.
   2. Enter the following command:  

          npm run build

          now-sdk build

   {#use-typescript-javascript-modules__substeps_tnx_kq1_vzb}

### O que Fazer Depois

Build and install the application to compile the TypeScript files into JavaScript modules and add the modules to the EcmaScript Module \[sys_module\] table. For more information, see [Build and installdeploy an application with the ServiceNow SDK](https://servicenow-prod.fluidtopics.net/GCQJKq4yOxXXoDY~k7hdzw "Build and installdeploy a local application developed with the ServiceNow SDK on a ServiceNow instance.").

## Add type definitions for APIs {#ariaid-title3}

Get type-ahead support for APIs and scriptable objects outside of Glide APIs.

### Antes de Iniciar

Role required: admin

### Por Que e Quando Desempenhar Esta Tarefa

Nota:  
You can download type definitions for most APIs, script includes, and other scriptable objects using the `now-sdk dependencies` command. For more information, see [Download module and script dependencies](https://servicenow-prod.fluidtopics.net/VksjUu5ubzAvjCk1G9w7qg#download-script-dependencies "Download TypeScript definitions for module and script dependencies to get IntelliSense support and validation for Glide APIs and script includes.").

Follow this procedure to manually add types definitions that the `now-sdk dependencies` doesn't download. You can declare modules directly in the ServiceNow SDK application to stub access to the APIs for type-ahead support. These modules aren't packaged in the application package, but they can be tracked in a source control repository for the
application and shared between developers.

### Procedimento

1. In Visual Studio Code, open your scoped application directory.
2. In your application, add a TypeScripe (.ts) file for type definitions.
3. In your TypeScript file, declare modules for APIs and scriptable objects.  
   This example declares a module for an API using the API namespace (`sn_app_api`):

       declare module '@servicenow/glide/sn_app_api' {
       	class AppStoreAPI {
       		static canUpgradeAnyStoreApp(): boolean
       	}
       } 

   This example declares a module to access objects defined in script includes using the scope of the script include (`x_1234_scope`):

       declare module '@servicenow/glide/x_1234_scope' {
       	class MyLogItemClass {
       		myLogFunction()
       	}
       }

4. In JavaScript modules in your application, import the declared modules.  
   This example imports the declared module for the AppStoreAPI.

       import { gs } from '@servicenow/glide'
       import { AppStoreAPI } from '@servicenow/glide/sn_app_api'

       export const canUpgradeStoreApp = function () {
       	var canUpgrade = AppStoreAPI.canUpgradeAnyStoreApp()
       	if (canUpgrade) {
       		gs.addInfoMessage(`You can upgrade store apps!`)
       	} else {
       		gs.addInfoMessage(`You cannot upgrade store apps!`)
       	}
       }

   This example imports the declared module for the MyLogItemClass object.

       import { MyLogItemClass } from '@servicenow/glide/x_1234_scope'

       export const myLogFunction = function (status) {
       	const myLogItem = new MyLogItemClass()
       	myLogItem.myLogFunction(status)
       }

   Nota:  
   Modules can access only global scriptable objects or scriptable objects in the same application scope.

