๐—ง๐˜†๐—ฝ๐—ฒ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—ง๐˜†๐—ฝ๐—ฒ ๐—”๐—ป๐—ป๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—š๐˜‚๐—ถ๐—ฑ๐—ฒ

Type annotations tell TypeScript what type of value a variable holds.

You use a colon after the name. Example: let age: number = 30.

These labels catch bugs during development.

Use these patterns:

Functions need annotations most. Example: function greet(name: string): void

Void means the function returns nothing.

Use the pipe symbol for multiple types. Example: let id: string | number

TypeScript removes all annotations during compilation. Your final JavaScript code is clean. This means zero runtime cost.

Write annotations when:

Skip them when:

Avoid these mistakes:

Source: https://dev.to/krunalkanojiya/how-to-use-type-annotations-to-explicitly-type-variables-in-typescript-5219