Tools

Editor setup

A *.tsx file is plain TSX. Any editor with TypeScript support reads it, with no plugin: VS Code uses its built-in TypeScript, and other editors use the TypeScript language server. idlip has no editor extension and no TypeScript plugin yet.

There are two kinds of check:

#tsconfig.json

Set jsx to preserve and jsxImportSource to idlip, so TypeScript reads the JSX types from idlip/jsx-runtime and leaves the views to the compiler.

json
{
  "compilerOptions": {
    "target": "es2023",
    "lib": ["es2023", "dom"],
    "module": "preserve",
    "moduleResolution": "bundler",
    "strict": true,
    "verbatimModuleSyntax": true,
    "allowImportingTsExtensions": true,
    "skipLibCheck": true,
    "jsx": "preserve",
    "jsxImportSource": "idlip",
    "noEmit": true
  },
  "include": ["src", "vite.config.ts"]
}

Add a typecheck script and run it in CI next to the build:

json
{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "typecheck": "tsc --noEmit"
  }
}

#Return types

A component may declare its return type with JSX.Element from idlip/jsx-runtime. The type exists only for TypeScript, so import it with import type.

import type { JSX } from 'idlip/jsx-runtime';

export default function Greeting(props: { name: string }): JSX.Element {
  let name = props.name;

  function rename(next: string) {
    name = next;
  }

  return <input value={name} on:input={(e) => rename(e.currentTarget.value)} />;
}

{
  "name": "Ada"
}

Event arrows are typed by element: in on:input on an <input>, e.currentTarget is an HTMLInputElement.

#idlip diagnostics

The Vite plugin compiles each module when Vite loads it. Each diagnostic is printed as <module id>:<line>:<column> <rule>: <message>, such as /src/todo.tsx:12:3 let-unassigned: .... A warning is logged and the build goes on. An error fails the load of the module, so vite build stops and vite dev reports it in the terminal.

To check every module without a build, call compile from idlip/compiler in a script and print its diagnostics. See idlip/compiler.

#VS Code