Skip to Content
NSUI

TypeScript and JSX

Type-safe nsui-* tags in TSX with NSUI's h() runtime, React 19 or plain DOM.

NSUI ships TypeScript types for every tag, element and function. Pick the JSX setup that matches your project, then add the matching type file.

Your projecttsconfigNSUI types
NetSuite SPA, or any page without React (classic factory)"jsx": "react", "jsxFactory": "h", "jsxFragmentFactory": "Fragment"types/jsx-classic.d.ts
No React, automatic runtime"jsx": "react-jsx", "jsxImportSource": "nsui"types/jsx-runtime.d.ts (picked up automatically)
React 19your React settingstypes/react.d.ts
Plain DOM, no JSX—types/nsui.d.ts

NSUI's h() creates real DOM nodes. There is no virtual DOM and no re-render: build the page once, then change elements directly.

Classic factory: h() (NetSuite SPA setup)

This is the setup Oracle's NetSuite SPA samples use, with NSUI's h() instead of UIF's runtime. It was verified live in a NetSuite SPA built with gulp, tsc and rollup.

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "react",
    "jsxFactory": "h",
    "jsxFragmentFactory": "Fragment",
    "paths": { "nsui": ["./vendor/nsui/types/nsui.d.ts"] }
  },
  "include": ["src/**/*", "vendor/nsui/types/jsx-classic.d.ts"]
}

Import h and Fragment in every .tsx file:

TSX
import { h, Fragment, toast } from 'nsui';
import type { GridColumn } from 'nsui';

const columns: GridColumn[] = [
  { key: 'item', label: 'Item' },
  { key: 'qty', label: 'Qty', type: 'number', editable: true, total: 'sum' },
];

export const Lines = () => (
  <nsui-card heading="Lines">
    <nsui-data-grid columns={columns} rows={[{ item: 'Bolt', qty: 4 }]} pageSize={10}
      oncellchange={(e) => toast(`${e.detail.key} → ${e.detail.value}`)} />
  </nsui-card>
);

paths points nsui at the type file in your copy of NSUI. Your bundler must resolve the same name to dist/nsui.esm.js (for rollup, a small alias plugin; see NetSuite SPA).

Automatic runtime: jsxImportSource

tsconfig.json
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "nsui",
    "paths": {
      "nsui": ["./vendor/nsui/types/nsui.d.ts"],
      "nsui/jsx-runtime": ["./vendor/nsui/types/jsx-runtime.d.ts"]
    }
  }
}

No h import is needed. The JSX namespace comes from nsui/jsx-runtime, so nothing is added to the global scope. Your bundler must resolve nsui/jsx-runtime to dist/jsx-runtime.js. This setup passes NSUI's type checks; it has not been run live in NetSuite yet.

React 19

React 19 renders custom elements directly and sets arrays and objects as properties.

TSX
<nsui-data-grid columns={columns} rows={rows} onselectionchange={(e) => setKeys(e.detail.keys)} />

For types, add types/react.d.ts to your project when react is installed in the same project. If TypeScript cannot resolve react from that file (for example, NSUI's types live outside your node_modules), copy its five lines into a .d.ts file in your project:

TypeScript
import type { NsuiElements } from './vendor/nsui/types/nsui';
declare module 'react' {
  namespace JSX { interface IntrinsicElements extends NsuiElements {} }
}

React 18 does not pass arrays to custom elements as properties. Use a ref and set el.rows = ..., or use React 19.

Plain DOM

types/nsui.d.ts adds every tag to HTMLElementTagNameMap, so queries return typed elements:

TypeScript
const grid = document.querySelector('nsui-data-grid')!;
grid.rows = lines;          // typed as the grid's rows
grid.refresh();
document.querySelector('nsui-dialog')!.show();
window.NSUI.toast('Saved'); // the plain-script build sets window.NSUI

Rules that apply to every setup

Events are lowercase on<event>

Write the event name as it is fired, in lowercase: onclick/onClick, onchange, ontabchange, onselectionchange, oncellchange, onrowclick, onsort, onclose. The event detail is typed:

TSX
<nsui-tabs ontabchange={(e) => setTab(e.detail.value)}>…</nsui-tabs>

Each component page lists its events under API → Events.

Arrays and objects: values or JSON strings

columns, rows and options accept a real array or a JSON string. Use real arrays in client code. JSON strings are for HTML written by a server (a Suitelet, a User Event, or React server rendering), because HTML cannot carry an array. Both work in every setup.

Annotate grid columns

A column list in a plain const widens type: 'currency' to string, which TypeScript rejects. Annotate it:

TypeScript
import type { GridColumn } from 'nsui';
const columns: GridColumn<Line>[] = [/* ... */];

Standard HTML tags are not checked

With the classic and automatic runtimes, div, p, section and other HTML tags accept any props. Only nsui-* tags are type-checked.

Passing type checks is not a live test

Type checks catch wrong prop names and values. They do not prove the page works in NetSuite. The C2C project's UIF pages passed tsc and hundreds of unit tests, then showed 8 runtime bugs on deploy. Test live in the target account before you ship.

NSUI is a community project. It is not an official Oracle NetSuite product. NetSuite is a trademark of Oracle.

On this page