TypeScript Compiler API

ts.sys

The default runtime System supplied by the TypeScript package in Node.js. It provides filesystem and environment operations used by compiler hosts. Check optional methods before using them; do not assume browser availability or native watcher semantics. Avoid mutating this shared object; spread and override selected methods for tests. Baseline: TypeScript 5.8.3, Node.js. Run as a local tooling script in a disposable directory; examples create files. Not a ByteMind CodeRunner example.

Formal Syntax & Structure

typescript syntaxtypescript
ts.sys: ts.System

Working Example

Example Snippettypescript
// Use a new empty directory. Install: npm install --save-exact typescript@5.8.3// File: example.cjs (omit this label)const ts = require("typescript");const assert = require("node:assert/strict");const fs = require("node:fs");const path = require("node:path");function put(name, text) {  fs.mkdirSync(path.dirname(name), { recursive: true });  fs.writeFileSync(name, text);}const file = path.resolve("data.txt");ts.sys.writeFile(file, "hello");assert(ts.sys.fileExists(file));assert.equal(ts.sys.readFile(file), "hello");assert.equal(ts.sys.readFile(path.resolve("missing.txt")), undefined);console.log("hello; missing is undefined");
// Run: node example.cjs// Expected stdout: hello; missing is undefined
TypeScript Reference