- TypeScriptNotesForProfessionals.pdf-
- TypeScript Classes.pdf
- TypeScript Control Flow Analysis.pdf
- TypeScript Interfaces.pdf
- TypeScript Types.pdf
- TypeScript was first introduced in 2012 by Microsoft.
- TypeScript helps catch errors early in the development process
- TypeScript is particularly useful for large-scale applications
- TypeScript is fully compatible with existing JavaScript code
npm install -g typescript
- tsc stands for TypeScript Compiler
- tsc is used to compile TypeScript code into JavaScript code
- tsc is the command-line interface for the TypeScript compiler
- tsc is used to compile a single file or adirectory of files
tsc filename.ts --watch
- tsc --init is a command that initializes a new TypeScript project by creating a tsconfig.json
tsc --init
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outDir": "build"
},
"include": ["src/**/*"]
}
- Number
let age: number = 30;
let price: number = 19.99;
- String
let name: string = "John Doe";
- Boolean
let isActive: boolean = true;
- Null
let nullValue: null = null;
- Undefined
let undefinedValue: undefined = undefined;
- BigInt
let bigIntValue: bigint = 12345678901234567890n;
- Symbol : Symbol() created by this function
- Unique Identifiers
- Preventing Name Collisions
- Private Properties
let symbolValue: symbol = Symbol("unique identifier");
- Void
let voidValue: void = undefined;
- Type aliases cannot be extended or implemented by classes
type Color = 'red' | 'green' | 'blue';
let color: Color = 'red';
- Type aliases in TypeScript allow you to create custom names for complex types, making your code more readable and maintainable.
type Person = {
name: string;
age: number;
};
let person: Person = {
name: "Alice",
age: 25,
};
type Result = number | string;
let value1: Result = 42;
let value2: Result = "Success";
type Calculator = (a: number, b: number) => number;
const add: Calculator = (x, y) => x + y;
type Point = {
x: number;
y: number;
};
type Color = {
color: string;
};
type ColoredPoint = Point & Color;
let coloredPoint: ColoredPoint = {
x: 10,
y: 20,
color: "red",
};
-
Interface Defined the bluePrint of the object
interface Person { name: string; // Required property age: number; // Required property email?: string; // Optional property readonly id: number; // Read-only property } -
If two interface have same name then will merge it
interface Book { name:string; price:number; } interface Book { size:number } const book:Book ={ name:"harry-potter", price:2324, size:44, } console.log(book);
-
union type allows you to define a variable that can hold multiple types
-
( | ) This operator is use
type Status = "active" | "inactive" | "pending";
-
Generic is a type that can work with any data type
-
Generic is use to create reusable function or class
function identity<T>(arg: T): T { return arg; } // Usage const num = identity<number>(42); // num is of type number const str = identity<string>("Hello"); // str is of type string -
Generic syntax in arrow function
// Generic arrow function const identity = <T>(arg: T): T => { return arg; }; // Using the generic arrow function const num = identity<number>(42); // num is of type number const str = identity<string>("Hello"); // str is of type string console.log(num); // Outputs: 42 console.log(str); // Outputs: Hello
I'm ASHUTOSH KUMAR FULLSTACK DEVELOPER
I specialize in creating modern and responsive web applications. With a strong passion for FULLSTACK development, I bring creative solutions to life through code and design. Additionally, I am a winner π of the GDG Patna WEB Hackathon
- Ashutosh kumar for creating and maintaining this repository.
