olix / Mycel / JavaScript and TypeScript developers
in development

Mycel for JavaScript and TypeScript developers

Arrow functions, ?., ??, async/await, generics and interface all carry over. What changes is a handful of words, and every one that changes gets an error that names the JavaScript or TypeScript habit.

Try Mycel in your browser →

Same

What carries over

From JavaScript: && || !, arrow functions x => x + 1, ?. and ??, // comments, optional semicolons, async/await. From TypeScript: interface, enum, class, generics <T>, type aliases, let x: Type = value, and x!. Closures infer parameter types from usage (double = x => x * 2). Async code works without Promise: an async fn returns the value directly.

tour_js.mycarrows, ?? and ?. behave as you expect · open in playground
double = x => x * 2
var user: String? = nil
print([1, 2, 3].map(double))
print(user ?? "anonymous")
print(user?.length)
output
[2, 4, 6]
anonymous
nil
Different

What is different

  • First assignment declares variables (x = 1); let binds immutably, and var binds mutably. There is no const.
  • == already compares values, so === and !== are not needed.
  • print(x) replaces console.log(x); nil replaces both null and undefined.
  • Strings interpolate with f"a {x}", not backticks and ${x}.
  • fn instead of function; self instead of this; no new: write Foo(); match instead of switch; x += 1 instead of x++; pub fn instead of export function.
  • TypeScript's number splits into Int (whole) and Float (decimal); string and boolean are String and Bool; lists are [Int], not number[]; any and unknown are Any.
  • Types are checked before the program runs. Mistakes are caught before code executes.
types.mycTypeScript types get a friendly fix-it · open in playground
let n: number = 42
compiler says
error [E0211]: `number` is TypeScript — Mycel has `Int` (whole) and `Float` (decimal)
  --> types.myc:1:8
  |
1 | let n: number = 42
  |        ^^^^^^
  why: no type named `number` exists in Mycel
  fix: see `mycel help habits`

1 error, 0 warnings
Habit fix-its

Every JS & TS habit and what Mycel says

Mycel's compiler recognises words and symbols from other languages. Instead of a generic syntax error you get the language it came from and the Mycel spelling. The full list for JavaScript and TypeScript is below; rows marked works are valid Mycel as you already write them.

habit.myca JavaScript habit gets a fix, not a puzzle · open in playground
function greet() {
  console.log("hello")
}
compiler says
error [E0101]: `function` is JavaScript — Mycel writes `fn name(args) { ... }`
  --> habit.myc:1:1
  |
1 | function greet() {
  | ^^^^^^^^
  why: this word comes from another language
  fix: see `mycel help habits`

1 error, 0 warnings
You writeMycel says
&& || !works: the same
x => x + 1works: the same
x?.y and x ?? yworks: the same
// comments and ; at line endworks: the same (semicolons are optional)
async / awaitworks: the same
=== and !===== is JavaScript — Mycel's == already compares values: write ==
function f() {}function is JavaScript — Mycel writes fn f() { ... }
const x = 1const is JavaScript — Mycel writes let (var for a value that changes)
console.log(x)console.log is JavaScript — Mycel writes print(x)
null / undefinedundefined is JavaScript — Mycel writes nil
this.xthis is JavaScript/Java — Mycel writes self.n
new Foo()new is JavaScript/Java — Mycel writes Foo()
switch (x) { case 1: }switch — Mycel writes match x { 1 => ... }
x++x++ — Mycel writes x += 1
template ${x}backticks are JavaScript — Mycel writes f"a {x}"
import x from 'y'import ... from is JavaScript — Mycel writes import std.fs
interface / enum / classworks: the same keywords
x! and x?.yworks: the same
generics <T>works: the same
let x: Type = valueworks: the same (types are Int, Float, String, Bool)
type Alias = ...works: the same
async/await, Promise-style codeworks: the same without Promise: async fn returns the value
numbernumber is TypeScript — Mycel has Int (whole) and Float (decimal)
string / booleanstring — Mycel writes String; boolean is Bool
any / unknownany is TypeScript — Mycel writes Any
const / functionconst is JavaScript/TypeScript — Mycel writes let
number[]number is TypeScript — Mycel writes [Int] for a list of whole numbers
x as numbernumber is TypeScript — Mycel has Int and Float
string[]Mycel writes a list type as [String]
export functionexport is TypeScript — Mycel writes pub fn f() { ... }

Every row is tested in the compiler, and mycel help habits prints the same list. See also the overview on the Mycel page.

Packages

Using npm packages: planned (coming in Phase B)

A compatibility engine so a Mycel program can use npm packages is planned, and the package manager ply already recognises the install flags. The planned forms are ply install --npm lodash and ply install --ts @types/node. Installing packages from other languages is marked as coming until Phase B lands, and Mycel itself is not released: there is nothing to download yet. The playground runs the real compiler in your browser with no packages.

Try it

Run the first example yourself

The Mycel playground opens in your browser. It runs the real compiler in a sandbox with no file, network or storage access, and nothing is sent to a server. For a guided walk through the language, read Learn Mycel.

More

Other starting points

Mycel is written so a program reads the same whichever language you learned first. Pick the guide closest to yours, or take the full tour.