Strongtalk
Strongtalk → TypeScript

Translate typed Smalltalk to TypeScript

Paste a workspace snippet or a whole file of classes. Strongtalk's type annotations become TypeScript types, and messages like ifTrue:, to:do: and collect: become if, for and map. Press Run both to check the result: the original runs in the Strongtalk VM and the translation runs as TypeScript, side by side.

Strongtalkworkspace code
TypeScriptloading the translator…

      
How it maps

Readable output, faithful where it matters

The declared types choose the translation: a variable typed <OrderedCollection[Int]> gets plain array code, while an untyped one goes through a small runtime helper that behaves like Smalltalk. Only the helpers a program uses are included, so every output is one file that runs on its own.

x <Int> ^<Self>
x: number): this

Type annotations become TypeScript types: Int, Str, Bool, generics, block types, unions.

a > b ifTrue: [a] ifFalse: [b]
a > b ? a : b

Control messages with literal blocks become statements or expressions.

1 to: n do: [:i | s := s + i]
for (let i = 1; i <= n; i++) {
  s = s + i;
}

to:do:, timesRepeat:, do: and whileTrue: become loops.

nums inject: 0 into: [:a :b | a + b]
nums.reduce((a, b) => a + b, 0)

Collection messages map to array methods; at: stays 1-based.

3 + 4 * 2
(3 + 4) * 2

Binary messages go left to right in Smalltalk, so parentheses are added where JavaScript precedence differs.

shapes do: [:s | s area > n ifTrue: [^s]]
for (const s of shapes) {
  if (s.area() > n) {
    return s;
  }
}

A ^ inside a block returns from the method, as in Smalltalk, even through closures.

Where it differs. Numbers become JavaScript numbers (exact integers up to 253; factorial switches to BigInt), / on integers gives a decimal instead of a fraction, characters and symbols become strings, and an OrderedCollection becomes an array (so it prints as #(…)). Messages with no known equivalent are kept as method calls and listed in the notes.
Three ways

Here, in the console, or in the environment

This page

Translation runs in your browser (the translator is compiled to WebAssembly); nothing is uploaded.

The console

The strongtalk command translates files and expressions.

$ strongtalk --to-ts shapes.dlt -o shapes.ts
$ strongtalk --to-ts -e '100 factorial'
$ node shapes.ts

The environment

In a workspace, select code and press → TypeScript (Ctrl+E). A class browser translates its whole class.

Open the environment →