Typescript By Hitesh(Youtube)¶
Reference Link : Youtube Link
Provides Type Safety¶
Example:
Typescript helps prevent such issues with type safety.
What does TypeScript do?¶
- Static Checking: Catches errors at compile-time instead of runtime.
- TypeScript is a development tool; the project still runs in JavaScript.
Installation¶
Refer to the official TypeScript documentation for installation instructions. docs
Running a TypeScript File¶
This command compiles the TypeScript file into a JavaScript file (index.js
).
Basic Syntax¶
Type Inference¶
In many cases, TypeScript can infer the type. For example:
Functions¶
Basic Function¶
Or using an arrow function:
Objects in Functions¶
function createUser({name: string, isPaid: boolean}): {name: string, price: boolean} {
return {name: "harsh", price: false};
}
Working with Types¶
You can define types for complex data structures.