Typescript
Typescript
1
Typescript:
1. Javascript দিয়েই তো আমরা সকল কাজ করতে পারি, তাহলে typescript ইউজ করার কারন কি?
2. Generics কি, কিভাবে কাজ করে?
3. Getter, Setter কি, কিভাবে কাজ করে?
4. Class এ super কিওয়ার্ড এর কাজ কি?
5. ধরুন আমি কোন Interface এর সকল প্রোপার্টি অপশনাল করতে চাচ্ছি, তাহলে কি করবো?
6.Type Assertion এবং Type Casting এর মধ্যে কি পার্থক্য রয়েছে?
7.TypeScript-এ Declaration Merging কি? এটি কীভাবে কাজ করে?
8.Union এবং Intersection Types কি? এটি কিভাবে ব্যবহার করা হয়?
9.TypeScript প্রজেক্টে কেন এবং কিভাবে tsconfig.json ফাইল ব্যবহার করা হয়?
10.React ডেভেলপমেন্টে TypeScript কীভাবে ব্যবহার করা হয় এবং এর পোজিটিভ এবং নেগেটিভ দিক কি?
1. Javascript দিয়েই তো আমরা সকল কাজ করতে পারি, তাহলে typescript ইউজ করার কারন কি?
In TypeScript classes, the super keyword is used to call methods or access properties of the
superclass (parent class). It is often used within the constructor of a subclass (child class) to call
the constructor of the superclass.
Example:
class Animal {
constructor(public name: string) {}
}
class Dog extends Animal {
constructor(name: string, public breed: string) {
super(name); // Call the constructor of the superclass
}
}
5. ধরুন আমি কোন Interface এর সকল প্রোপার্টি অপশনাল করতে চাচ্ছি, তাহলে কি করবো?
To make all properties of an interface optional in TypeScript, we can use the question mark (?)
after each property name.
Example:
interface Person {
name?: string;
age?: number;
}
7. TypeScript-এ Declaration Merging কি? এটি কীভাবে কাজ করে?
Declaration merging in TypeScript allows us to extend the definition of existing types,
interfaces, enums, or namespaces across multiple declarations. This feature enables you to
split the definition of entities across multiple files or libraries without needing to redeclare
them.
8. Union এবং Intersection Types কি? এটি কিভাবে ব্যবহার করা হয়?
Union and intersection types are two advanced type concepts in TypeScript:
Union Types (|): A type formed by combining multiple types, where a value of the
union type can be any of the specified types.
Intersection Types (&): A type formed by combining multiple types, where a value of the
intersection type must satisfy all of the specified types.
Example:
type NumOrStr = number | string;
type Person = { name: string } & { age: number };
9.TypeScript প্রজেক্টে কেন এবং কিভাবে tsconfig.json ফাইল ব্যবহার করা হয়?
In a TypeScript project, the tsconfig.json file is used to configure the TypeScript
compiler (tsc). It specifies compiler options, including target JavaScript version, module
system, output directory, and more. By configuring tsconfig.json, we can tailor
TypeScript compilation to our project's specific requirements.
10. React ডেভেলপমেন্টে TypeScript কীভাবে ব্যবহার করা হয় এবং এর পোজিটিভ এবং নেগেটিভ দিক কি?
In React development, TypeScript can be used to add static typing and other benefits to our
codebase.
Positive aspects include:
● Type Safety: TypeScript helps catch errors during development, reducing bugs and
improving code quality.
● Enhanced Tooling: TypeScript provides better IDE support, making code navigation
and refactoring easier.
● Code Documentation: With explicit type annotations, TypeScript improves code
readability and documentation.
negative aspects may include:
● Learning Curve: Learning TypeScript and setting up a TypeScript project may require
some initial effort.
● Compatibility: TypeScript may have compatibility issues with certain libraries or
frameworks, although the situation is improving over time.
● Build Time: Adding static typing may slightly increase build times, especially in larger
projects.