🌱Aadam's Garden


Search IconIcon to open search


Last updated Jul 19, 2022

Most Browsers don’t support TypeScript. That’s why we need to compile it to JavaScript first, before shipping.

# Type Annotations

Type Annotations help reduce runtime errors.

// string, number, boolean, null, undefined
const myName: string = "";

It can also infer data types, but only when the variable is initialized.

# Union Types

They allow you to specify multiple data types for a variable. Use | to specify multiple types.

let myName: string | null = null;
myName = 'test';

# Decorators

Decorators are functions for extending business logic or adding metadata.

To enable them in TypeScript, add the "experimentalDecorators": true option into the tsconfig.json file under "compilerOptions": {…}.

# Difference b/w Expressions & String Interpolation

Expressions are the code inside the curly brackets
String Interpolation is the process of replacing placeholders into string values
"The expression {{ name }} is interpolated into John."