
# TypeScript

> Nitro is TypeScript-first: write your config, handlers, and server code in TypeScript with zero setup.

Nitro is written in TypeScript and bundles your server code, so `.ts` files work out of the box in development and production, with no separate compile step. The TypeScript compiler is only needed for type checking (for example `tsc --noEmit` in CI).

All public utilities ship with types:

```ts [nitro.config.ts]
import { defineConfig } from "nitro";

export default defineConfig({
  // Fully typed config with completions
});
```

```ts [server/routes/hello.ts]
import { defineHandler } from "nitro";

export default defineHandler((event) => {
  return { hello: "world" }; // Typed event and inferred return type
});
```

Types (such as `NitroConfig`, `NitroModule`, or `NitroRuntimeConfig`) are exported from `nitro/types`:

```ts
import type { NitroModule } from "nitro/types";
```

## `tsconfig.json` setup

Nitro provides a shareable TypeScript configuration you can extend from:

```json [tsconfig.json]
{
  "extends": "nitro/tsconfig"
}
```

It enables modern, strict defaults matching how Nitro bundles your code: `strict` type checking, bundler module resolution, `noEmit`, `verbatimModuleSyntax`, and `allowImportingTsExtensions` (so you can use explicit `.ts` extensions in imports). You can override any option by adding your own `compilerOptions` on top:

```json [tsconfig.json]
{
  "extends": "nitro/tsconfig",
  "compilerOptions": {
    "jsx": "react-jsx"
  }
}
```

## `typescript` config options

| Option | Default | Description |
| --- | --- | --- |
| `tsConfig` | Project `tsconfig.json` | TypeScript config used by the bundler for JSX options and path aliases. |

Nitro reads your project's root `tsconfig.json` to pick up JSX settings (`jsx`, `jsxFactory`, `jsxFragmentFactory`, `jsxImportSource`) and path aliases. Set `typescript.tsConfig` to override it:

```ts [nitro.config.ts]
import { defineConfig } from "nitro";

export default defineConfig({
  typescript: {
    tsConfig: {
      compilerOptions: {
        jsx: "react-jsx",
      },
    },
  },
});
```
