Values in TypeScript
Our first example will demonstrate various value types in TypeScript including strings, numbers, and booleans. Here’s the full source code:
To run the program, save it as values.ts
and use ts-node
(assuming you have TypeScript and ts-node installed):
TypeScript is a statically typed superset of JavaScript, so it shares many characteristics with JavaScript. Unlike some other languages, TypeScript (and JavaScript) use a single number type for both integers and floating-point numbers.
TypeScript also provides type inference, meaning you don’t always have to explicitly declare types. However, you can add type annotations for clarity:
These examples demonstrate basic value types in TypeScript. As you progress, you’ll encounter more complex types and structures that TypeScript offers.