@hitc/netsuite-types: TypeScript Typings for SuiteScript 2.0

repository·master·Indexed 41 days ago

https://github.com/headintheclouddev/typings-suitescript-2.0

TypeScript type definitions for NetSuite's SuiteScript 2.0 API (version 2026.2.2). Provides IDE features such as autocomplete, type-checking, and documentation for developers writing SuiteScript in TypeScript, including support for entry points and N/ modules.

Tokens
1.1K
Snippets
5
Records
5
Agent score
1%

What's inside @hitc/netsuite-types

  1. How to write SuiteScript with typings

    master

    When writing scripts, include the appropriate JSDoc annotations (@NAPIVersion and @NScriptType) at the top of the file. Use the import type {EntryPoints} from 'N/types'; statement to access type definitions for your script's entry point functions. This allows your IDE to provide autocomplete and type-checking for the context argument and other SuiteScript modules.

    /**
     * @NAPIVersion 2.0
     * @NScriptType ClientScript
     */
    
    import type {EntryPoints} from 'N/types';
    
    export let pageInit: EntryPoints.Client.pageInit = (context: EntryPoints.Client.pageInitContext) => {
      // Your IDE will now autocomplete from the context argument.
      // For instance, use this to access context.mode and context.currentRecord
    }
  2. Configure TSC (TypeScript Compiler) for SuiteScript

    master

    To use the typings, you must configure your tsconfig.json to use the amd module format and es5 target. Crucially, you must set up baseUrl and paths so the compiler can resolve the NetSuite module aliases (starting with N/) to the library in your node_modules folder.

    {
      "compilerOptions": {
        "module": "amd",
        "target": "es5",
        "moduleResolution":"node",
        "sourceMap": false,
        "newLine": "LF",
        "experimentalDecorators": true,
        "baseUrl": ".",
        "lib": ["es5", "es2015.promise", "dom"],
        "paths": {
          "N": ["node_modules/@hitc/netsuite-types/N"],
          "N/*": ["node_modules/@hitc/netsuite-types/N/*"]
        }
      },
      "exclude": ["node_modules"]
    }
  3. Suitelet Script Example

    master

    A complete example of a Suitelet script. This demonstrates importing N/record and using the EntryPoints.Suitelet.onRequest type for the onRequest entry point.

    /**
     * @NApiVersion 2.x
     * @NScriptType Suitelet
     */
    
    import type {EntryPoints} from 'N/types';
    import * as record from 'N/record';
    
    export let onRequest: EntryPoints.Suitelet.onRequest = (context: EntryPoints.Suitelet.onRequestContext) => {
        let folder = record.load({type: 'folder', id: 36464});
        let allfields = folder.getFields().join(', ');
        context.response.write(`<br>all fields: ${allfields}`);
    };
  4. User Event Script Example

    master

    A complete example of a User Event Script using the typings. Note the use of EntryPoints.UserEvent for the function signature and N/log for logging.

    /**
     * @NAPIVersion 2.0
     * @NScriptType UserEventScript
     */
    
    import type {EntryPoints} from 'N/types';
    import * as log from 'N/log';
    
    export let beforeSubmit: EntryPoints.UserEvent.beforeSubmit = (context: EntryPoints.UserEvent.beforeSubmitContext) => {
        let x = context.newRecord.getValue({fieldId: 'companyname'});
        log.audit('value', `companyname is: ${x}`);
    };