0% found this document useful (0 votes)
48 views

Typescript

Uploaded by

italimbd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Typescript

Uploaded by

italimbd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Interview Questions:

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 ইউজ করার কারন কি?

Although JavaScript allows us to accomplish various tasks, TypeScript offers several


advantages:
● Static Typing: TypeScript allows developers to define types for variables, parameters, and
return values, which helps catch errors during development and provides better code
documentation.
● Enhanced Tooling: TypeScript provides advanced IDE support, including code completion,
refactoring tools, and better navigation through codebases, which can improve developer
productivity.
● Code Maintainability: With static typing and explicit type annotations, TypeScript code tends
to be more readable and maintainable, especially in large codebases.
● Modern Features: TypeScript supports modern JavaScript features along with additional
features like interfaces, enums, decorators, and more, which are not yet fully supported in
all JavaScript environments.

2. Generics কি, কিভাবে কাজ করে?


Generics in TypeScript allow us to create reusable components that can work with various
data types rather than a single one. Generics are declared using angle brackets (<>) and can be
used in functions, classes, and interfaces. They enable us to define types that are determined by
the client code when they are instantiated or called.
function identity<T>(arg: T): T {
return arg;
}
let output = identity<string>("hello");
3. Getter, Setter কি, কিভাবে কাজ করে?
Getter and setter methods allow us to define custom behavior when accessing or modifying the
properties of an object in TypeScript classes.
● Getter is a method that is used to get the value of a property of an object in typescript class.
● Sette is a method that is used to set the value of a property.
● Example:
class Person {
private _name: string;

get name(): string {


return this._name;
}

set name(value: string) {


this._name = value;
}
}

let person = new Person();


person.name = "John";
console.log(person.name); // Output: John

4. Class এ super কিওয়ার্ড এর কাজ কি?

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;
}

​ 6. Type Assertion এবং Type Casting এর মধ্যে কি পার্থক্য রয়েছে?



​ Type assertion in TypeScript is a way to tell the compiler about the type of a variable when
we know more about the type than TypeScript does. It is done by using the as keyword or
the angle-bracket syntax (<>).
​ Type casting, on the other hand, refers to the conversion of one data type to another data
type. In TypeScript, type casting is not explicitly supported, but we can achieve similar
behavior using type assertion.


​ 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.

You might also like