netsuite-types
TypeScript type definitions for the SuiteScript 2.1 API, generated from the official NetSuite JSDoc source.
- Ambient
declare module "N/...". - Typed AMD
define()/require()with module-name inference. - Global objects typed without an import:
define,require,log,util(JSON/Promise/Iteratorcome from the TS standard lib). - Entry-point context types (
UserEvent,MapReduce,Suitelet, …) viaN/types. - Re-generatable from a new SuiteScript snapshot — run
npm run generate.
Status
Covers the full SuiteScript 2.1 module surface — every N/... module in the
source (~76 modules, some of them are not described in offcial docs, thus can not be used in suitescripts), plus hand-authored entry-point contexts (N/types),
N/currentRecord, and global objects (log, util, define, require).
Any module not yet typed resolves to unknown (non-breaking).
IDE setup
1. Install (it's a dev-only dependency — types never ship to NetSuite):
npm install --save-dev netsuite-types2. Point TypeScript at the types via the types array (recommended):
// tsconfig.json
{
"compilerOptions": {
"module": "amd", // NetSuite's runtime is AMD (as of Jun 2026)
"target": "es2023",
"removeComments": false,
"ignoreDeprecations": "6.0",// only if on TS 6.x (6.x warns about module:amd deprecation in 7.x)
"types": ["netsuite-types"]
}
}Alternative (instead of the types array): a triple-slash directive in any file:
/// <reference types="netsuite-types" />3. Build & deploy. TypeScript compiles your .ts to AMD .js
(define([...], …)), and the SuiteCloud CLI / SDF deploys that JS to
NetSuite. The types are compile-time only — they never reach the account.
Writing a script
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
// <-- blank line REQUIRED so the banner
import type { EntryPoints } from "N/types"; // survives into emitted JS
import record = require("N/record");
import log = require("N/log");
export function afterSubmit(ctx: EntryPoints.UserEvent.afterSubmitContext): void {
const rec = record.load({ type: "salesorder", id: ctx.newRecord.id });
log.audit({ title: "id", details: rec.id });
}Regenerating from a new SuiteScript snapshot
The generator auto-discovers every module in the source — point it at the
unzipped folder or the NetSuite .zip download directly:
npm run generate -- /path/to/SuiteScript-2.1.zip # straight from the zip
npm run generate -- "/path/to/SuiteScript 2.1 API" # or an unzipped folder
NS_SOURCE=/path/to/source npm run generate # or via env var
npm run check # type-check the outputModules are found by their @module N/... tag (plus a couple of global modules
named in EXTRA_MODULES). A small SKIP list in generator/index.js excludes
internal helpers. No module needs to be listed by hand.
Patching missing/undocumented API
overrides/patches.js (a JS module, so fields are reusable) injects things
NetSuite's JSDoc omits. Define a field once and apply it to many methods:
const disableTriggers = { name: "disableTriggers", type: "boolean", optional: true,
doc: "Undocumented. Skips triggers. Default false." };
module.exports = {
methodOptions: {
"N/record": {
Record: { save: [disableTriggers] }, // instance method (Record.save)
"*": { submitFields: [disableTriggers] }, // module fn (record.submitFields)
},
},
};Patched methods get a named options interface so the doc shows on hover.
Override-only modules (not in the source)
Some documented modules are absent from a given source snapshot (e.g.
N/currentRecord). Drop a hand-authored overrides/N/<module>.d.ts and the
generator emits it as a normal module — wired into the barrel and the typed
define() map like any other. When NetSuite restores the module to the zip,
delete the override and the generator produces it from source instead.
There are three override kinds under overrides/N/:
<module>.d.ts— full replacement of a generated module, or an override-only module with no source file.<module>.augment.d.ts— declaration-merged additions to a generated module.types.d.ts— the entry-point contexts (N/types).
Project layout
generator/ JSDoc -> .d.ts generator (TS Compiler API + regex param parser)
index.js auto-discovers modules from a folder or .zip
overrides/ hand-authored pieces:
N/types.d.ts entry-point contexts (whole-file override)
patches.js reusable patches: missing props + method options
dist/ generated package output (committed/published)
test/ an example project that compiles against dist/