Tsonic GitHub

JavaScript Runtime Compatibility (@tsonic/js)

Tsonic targets the .NET BCL by default. If you want JavaScript-style runtime APIs (like JSON, Math, timers, Date, RegExp, JS arrays, etc.), use @tsonic/js.

This is not Node.js. It’s a JS-semantics runtime implemented in .NET so TypeScript code can opt into familiar JavaScript behavior where needed.

Table of Contents

Getting Started

  1. Getting Started - enable @tsonic/js in a Tsonic project (--surface @tsonic/js)
  2. Importing APIs - natural surface usage + optional direct imports

APIs

  1. console
  2. JSON
  3. Math
  4. Timers
  5. Globals (global functions like parseInt)
  6. JSArray
  7. Map/Set/WeakMap/WeakSet
  8. ArrayBuffer + Typed Arrays
  9. Date
  10. RegExp
  11. Number
  12. String

Overview

In JS surface projects you can write natural JS with no explicit runtime imports:

export function main(): void {
  const value = JSON.parse<{ x: number }>('{"x": 1}');
  console.log(JSON.stringify(value));
}

Direct imports from @tsonic/js/index.js are still supported.

Relationship to @tsonic/nodejs

  • @tsonic/js provides JavaScript runtime APIs (JSON, Math, Date, timers, JS collections).
  • @tsonic/nodejs provides Node-style APIs (fs/path/http/crypto/process, etc.) implemented on .NET.

You can enable either or both in a project.