Languages3 min read

TypeScript

TypeScript on Spinini

Spinini supports TypeScript for both Node.js backends and React frontends. The TypeScript template comes pre-configured so you can start writing typed code immediately.

Getting started

Select the TypeScript template. It includes:

  • tsconfig.json with sensible defaults
  • ts-node for running .ts files directly
  • @types/node for Node.js type definitions
  • Running TypeScript files

    npx ts-node src/index.ts
    # or
    npm run dev  # uses ts-node-dev for watch mode

    Building to JavaScript

    npx tsc
    node dist/index.js

    tsconfig.json

    A minimal config for Node.js:

    {
      "compilerOptions": {
        "target": "ES2022",
        "module": "commonjs",
        "outDir": "dist",
        "rootDir": "src",
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true
      },
      "include": ["src/**/*"]
    }

    Type-checking

    The editor runs the TypeScript language server, so type errors appear inline as you type — no need to run tsc to find them.

    Adding type packages

    npm install -D @types/express @types/cors

    With React

    Use .tsx extensions and install @types/react. Both the Vite + React and Next.js templates ship with TypeScript pre-configured.