DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Juan Carlos
Juan Carlos

Posted on

Nim for TypeScript Devs

Feature TypeScript Nim
Execution model JavaScript code (Compiler) JavaScript code (Compiler)
Written using TypeScript Nim
License Apache MIT
Version (Mayor) 3.x 1.x
Typing Static Static
Meta-programming ❎ #issue-13252, Decorators are limited βœ”οΈ template, macro
int8/16/32/64 types ❎ βœ”οΈ
float32/float64 types ❎ βœ”οΈ
Char types ❎ βœ”οΈ
Subrange types ❎ #issue-225324972 βœ”οΈ
JSON types ❎ #issue-56296923 βœ”οΈ
Regex types ❎ #issue-128264906 βœ”οΈ
Option types ❎ βœ”οΈ
Dependent types ❎ βœ”οΈ
Operator Overloading ❎ βœ”οΈ
Custom Operators ❎ βœ”οΈ
Enum types βœ”οΈ βœ”οΈ
Immutability Limited, readonly keyword βœ”οΈ
Function Arguments Immutability Mutable Immutable
Full DOM API βœ”οΈ βœ”οΈ
NodeJS integration βœ”οΈ βœ”οΈ
Generics βœ”οΈ βœ”οΈ
Type inference βœ”οΈ βœ”οΈ
Closures βœ”οΈ βœ”οΈ
Object-Oriented βœ”οΈ βœ”οΈ
Methods βœ”οΈ βœ”οΈ
Exceptions βœ”οΈ βœ”οΈ
Anonymous Functions βœ”οΈ βœ”οΈ
Arrow Functions βœ”οΈ βœ”οΈ
Array Comprehensions βœ”οΈ βœ”οΈ
Formatted String Literals βœ”οΈ βœ”οΈ
FFI βœ”οΈ JS only βœ”οΈ C/C++/JS
Async βœ”οΈ βœ”οΈ
Regex βœ”οΈ βœ”οΈ
Self-Documentation comments βœ”οΈ βœ”οΈ
Package Publishing βœ”οΈ βœ”οΈ
Package Manager βœ”οΈ βœ”οΈ
Code AutoFormatter βœ”οΈ via NPM βœ”οΈ Nimpretty
Syntax similar to JavaScript CoffeeScript or Python

Alt Text

Variables

Creating a new variable uses var or let or const.
Nim has immutability and compile-time function execution.
You can assign functions to variables.

  • const is different from TypeScript by being truly immutable.
Declaration Compile-Time Run-Time Immutable Requires Assignment
var ❎ βœ”οΈ ❎ ❎
let ❎ βœ”οΈ βœ”οΈ βœ”οΈ
const βœ”οΈ ❎ βœ”οΈ βœ”οΈ

Compile-Time Function Execution

Nim has Compile-Time Function Execution that allows you to run Backend-like code at compile-time and use it on Frontend at run-time.
Compile-time FFI is also possible, you can pull data from C/C++ libs at compile-time and use it on Frontend at run-time.
Most code that works at compile-time and NimScript also tends to work for Frontend.

Example: Compile-time recursive file system walk module.

Svelte

Nim has some similarities with Svelte for Frontend, but at the time of writing Svelte does not fully supports TypeScript.
Svelte can not do Backend (is not designed to).

Build Modes

Feature Release Build Debug Build
Speed Fast Slow
File Size Small Big
Optimized βœ”οΈ ❎
Tracebacks ❎ βœ”οΈ
Run-time checks ❎ βœ”οΈ
Compile-time checks βœ”οΈ βœ”οΈ
assert ❎ βœ”οΈ
doAssert βœ”οΈ βœ”οΈ
  • Once compiled it wont need Nim anymore, 100% dependency-free.

Hello World

echo "Hello World"
Enter fullscreen mode Exit fullscreen mode

Console Hello World:

console.log("Hello World")
Enter fullscreen mode Exit fullscreen mode

Thank you for playing

There's bridged Gitter, Matrix, Telegram, IRC, Discord for Nim, come say Hi.

Nim Homepage
Learn Nim today.
Grupo de Telegram en EspaΓ±ol.

πŸ‘‘

Top comments (0)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: