Registry / serialization / ts2nim

ts2nim

JSON →
library0.0.31jsnpmunverified

A TypeScript to Nim transpiler that converts TypeScript source code (and JavaScript via TypeScript ESTree) into valid, pretty Nim code. The 0.0.31 release is currently in early development with limited semantic analysis; it focuses on syntax translation and basic type mapping (e.g., number→float, Array→seq, null→nil). The tool also generates wrapper code from .d.ts files using importcpp pragmas. Compared to alternatives like dts2nim, ts2nim directly translates full TypeScript sources rather than just type definitions. It is intended to expand Nim's JavaScript backend ecosystem by reusing existing TypeScript/JavaScript libraries. Note that the project does not resolve dependencies and requires manual post-translation adjustments.

npm install ts2nim
INSTALL
IMPORT
SIG · TS2NIM
T
ts2nim
serializationjavascriptv0.0.31
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import ts2nim from 'ts2nim'
ESM default import. CommonJS require works: const ts2nim = require('ts2nim').
CLI
import { cli } from 'ts2nim'
CLI entry point can also be invoked via npx ts2nim.
Type
import type { TranspileOptions } from 'ts2nim'
TypeScript types are shipped with the package.

Demonstrates programmatic usage: transpile a simple TypeScript function to Nim using the default API.

import ts2nim from 'ts2nim'; import { readFileSync, writeFileSync } from 'fs'; const typescriptCode = ` function greet(name: string): string { return 'Hello, ' + name; } `; ts2nim.transpile(typescriptCode, { mode: 'source' }).then(result => { writeFileSync('greet.nim', result.output); console.log('Transpiled successfully'); });
ts2nim --version
Debug
Known issues
gotchaThe transpiler does not resolve external dependencies; it only translates the given source files.
fix
Manually import and translate required modules, or use .d.ts files for wrapper generation.
affects: >=0.0.1
gotchaType inference for native types (e.g., number as int vs float) is not yet implemented; all numbers become float.
fix
Manually adjust number types in generated Nim code.
affects: >=0.0.1
gotchaMultiple inheritance from TypeScript classes is not supported; Nim does not support multiple inheritance.
fix
Refactor TypeScript classes to avoid multiple inheritance, or use composition instead.
affects: >=0.0.1
gotchaRest parameters in TypeScript become openArray[T] in Nim, which may require manual adjustment.
fix
Review generated Nim code for rest parameters and adjust types as needed.
affects: >=0.0.1
gotchaAsync functions are translated with {.async.} pragma but require the asyncdispatch or asyncjs module to be imported manually.
fix
Add import asyncdispatch or import asyncjs to the top of generated Nim file.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'ts2nim'
The package is not installed, or the import path is incorrect.
fix
Run npm install ts2nim and use correct import: import ts2nim from 'ts2nim'.
TypeError: ts2nim.transpile is not a function
Incorrect import; transpile is a method on the default export, not a named export.
fix
Use import ts2nim from 'ts2nim' and call ts2nim.transpile().
SyntaxError: Unexpected token ':' - expected '(' in Nim code
TypeScript type annotations are not fully removed or converted incorrectly for certain constructs.
fix
Manually review and fix the generated Nim code, especially around function signatures and type casts.
Error: TSMethodSignature not supported in current mode
Using .d.ts files requires mode set to 'declaration' or specific options.
fix
In the CLI, use --declaration flag or set mode: 'declaration' in programmatic API.
Upgrade
Version history
0.0.31latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
ts2nim — npm install ts2nim · libregistry