๐ ๐ฎ๐๐๐ฒ๐ฟ๐ถ๐ป๐ด ๐ง๐๐ฝ๐ฒ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐ง๐๐ฝ๐ฒ๐
JavaScript is dynamic. You put a number in a variable. Then you put a string in it. This causes bugs.
TypeScript fixes this. It defines the shape of your data. It finds errors before you run the code.
Use these types to write better code:
Primitives
- boolean: Use for true or false. Avoid the Boolean object.
- number: Use for all numbers. Use bigint for huge integers.
- string: Use for text.
Structures
- Interface: Best for public contracts. Others extend these.
- Class: Use when you need both a type and a value.
- Enum: Use for a fixed set of choices.
Collections
- Array: A list of the same type.
- Tuple: A list with a fixed size and order.
Safety Types
- Any: Stops all checks. It is dangerous. Avoid it.
- Unknown: A safe top type. You must verify the type before use.
- Never: Use for impossible values.
Pick the right type. Stop bugs early.
Source: https://dev.to/yuripeixinho/tipos-em-tyopescript-j9h