Ayanokoji
Commands

TypeScript

TypeScript is a language that builds on JavaScript by adding syntax for type declarations and annotations. It is a superset of JavaScript and is maintained by Microsoft.

Documentation

Usage

npx ayanokoji typescript init

This command initializes TypeScript in your project through an interactive process where you can configure:

  • Strictness settings (strict mode, noUncheckedIndexedAccess, noImplicitOverride)
  • Transpilation method (tsc vs other build tools)
  • Runtime environment (browser DOM vs Node.js)
  • Library configuration
  • Monorepo settings
  • Dependencies to install (TypeScript, @types/node, @types/bun, @cloudflare/workers-types)

The command creates a tsconfig.json with optimized defaults including:

  • ES2022 target
  • Module resolution for Node.js/ESM
  • JSON module support
  • Source map generation
  • Strict type checking (optional)

The command will fail if a tsconfig.json file already exists in your project.

TSConfig Options

The generated tsconfig.json includes carefully selected options:

Base Options

  • target: "es2022" - Compiles to modern JavaScript features
  • esModuleInterop: true - Enables cleaner imports from CommonJS modules
  • skipLibCheck: true - Skips type-checking of declaration files for better performance
  • allowJs: true - Allows JavaScript files to be imported
  • resolveJsonModule: true - Enables importing JSON files
  • moduleDetection: "force" - Treats each file as a module
  • verbatimModuleSyntax: true - Ensures explicit imports/exports
  • erasableSyntaxOnly: true - Limits TypeScript syntax to features that can be easily erased to JavaScript. Disallows enums, namespaces with runtime code, parameter properties in classes, and non-ECMAScript import/export assignments.
    // ❌ error: An `import ... = require(...)` alias
    import foo = require("foo");
    // ❌ error: A namespace with runtime code.
    namespace container {
      foo.method();
      export type Bar = string;
    }
    // ❌ error: An `import =` alias
    import Bar = container.Bar;
    class Point {
      // ❌ error: Parameter properties
      constructor(public x: number, public y: number) {}
    }
    // ❌ error: An `export =` assignment.
    export = Point;
    // ❌ error: An enum declaration.
    enum Direction {
      Up,
      Down,
      Left,
      Right,
    }

Strictness Options (Optional)

Build Options

When using tsc:

When using other build tools:

Library Options (Optional)

  • composite: true - Tells TypeScript to emit .tsbuildinfo files. This tells TypeScript that your project is part of a monorepo, and also helps it to cache builds to run faster.
  • declaration: true - Tells TypeScript to emit .d.ts files. This is needed so that libraries can get autocomplete on the .js files you're creating.
  • declarationMap: true - Generates source maps for .d.ts files. These are needed so that when consumers of your libraries are debugging, they can jump to the original source code using go-to-definition.
Edit on GitHub

Last updated on

On this page