TYPESCRIPT Flashcards

1
Q

What is TypeScript? And why use it ?

A

TypeScript is a syntactic superset of JavaScript which adds static typing.

This basically means that TypeScript adds syntax on top of JavaScript, allowing developers to add types.

allows specifying the types of data being passed around within the code, and has the ability to report errors when the types don’t match.

For example, TypeScript will report an error when passing a string into a function that expects a number. JavaScript will not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the benefits of using TypeScript over plain JavaScript?

A

-catching errors during development
-providing better tooling and autocompletion
-enabling easier refactoring of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the concept of static typing in TypeScript.

A

explicitly define types for variables, function parameters, and return values, helping catch type-related errors during compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you define types and interfaces in TypeScript?

A

Types and interfaces in TypeScript allow you to define the structure and shape of objects, providing better documentation and enforcing type checks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are generics in TypeScript and how can they be helpful?

A

Generics in TypeScript allow you to create reusable components or functions that can work with different types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does TypeScript handle union and intersection types?

A

Union types in TypeScript allow a variable to have more than one type, while intersection types combine multiple types into a single type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the basic data types in TypeScript?

A
  • TypeScript supports the same basic data types as JavaScript, such as number, string, boolean, null, undefined, and symbol.
  • It also supports additional data types such as any, void, and never.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a class in TypeScript?

A
  • A class is a blueprint for creating objects that has properties and methods.
  • It is a core feature of object-oriented programming in TypeScript.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an interface in TypeScript?

A
  • An interface is a way to define a contract in TypeScript.
  • It defines the shape of an object and its properties and methods.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a module in TypeScript?

A
  • A module is a way to organize code in TypeScript.
  • It allows you to encapsulate code and prevent naming collisions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is type inference in TypeScript?

A

Type inference is a feature in TypeScript that allows the compiler to automatically determine the type of a variable based on its value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is type assertion in TypeScript?

A
  • Type assertion is a way to tell the compiler what the type of a variable is.
  • It is used when the compiler cannot determine the type of a variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between “interface” and “type” in TypeScript?

A
  • An interface is a way to define a contract for an object, while a type is a way to define a type alias.
  • An interface can be implemented by a class, while a type alias cannot.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between “any” and “unknown” in TypeScript?

A
  • “any” is a type in TypeScript that allows any value to be assigned to it.
  • “unknown” is a type in TypeScript that is more restrictive than “any”. It cannot be assigned to any other type without first being checked.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

pros of typescript

A

code that has less errors
cleaner
more readable
client and server side
optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is a tuple?

A

A tuple is a typed array with a pre-defined length and types for each index.

17
Q

what is a tuple?

A

A tuple is a typed array with a pre-defined length and types for each index.