๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ง๐๐ฝ๐ฒ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐ฃ๐ฟ๐ถ๐บ๐ถ๐๐ถ๐๐ฒ ๐ง๐๐ฝ๐ฒ๐
You need types to write safe code. TypeScript uses 7 primitive types. These are the basic building blocks of your data.
The 7 types are:
- string: text like names or emails.
- number: all numbers and decimals.
- boolean: true or false.
- null: an intentional empty value.
- undefined: a value not set yet.
- bigint: huge whole numbers.
- symbol: unique identifiers.
Use string, number, and boolean most of the time.
Follow these rules for better code:
- Use lowercase names. Use string, not String.
- Let TypeScript guess the type if the value is clear.
- Use null when you choose to leave a value empty.
- Use undefined for missing values.
Numbers in TypeScript cover everything. You do not need separate types for integers or floats.
BigInt handles numbers larger than the standard number type. It requires ES2020 or higher.
Write clear types to stop errors before they happen.