Basic Syntax To Define A Variable With A Type In TypeScript

[!INFO]-
topic: πŸ¦’ TypeScript
links: What is TypeScript
source: TypeScript course by the native web
tags: #permanent-noteΒ #published

Last Modified: =dateformat(this.file.mtime, "MMM. dd, yyyy - HH:mm")


To define a variable with a type in TypeScript, you define the type with a : like this:

let pi: number;
pi = 3.14;

TypeScript can defer a type. So if you add two numbers together, the result is also a number.

const result = 42 + 1; // result has the type number