TypeScript Flashcards

1
Q

What is TypeScript?

A

TypeScript is a superset of JavaScript that adds static typing.

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

Static Typing

A

TypeScript allows you to define variable types, making code more predictable and easier to debug.

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

Transpilation

A

TypeScript code is compiled into JavaScript for execution in browsers or Node.js.

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

TypeScript File Extension

A

TypeScript files use the .ts extension.

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

Benefits of TypeScript

A

Improves code quality, better error detection, supports modern JS features.

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

Interfaces

A

Used to define contracts for objects, specifying their structure.

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

Classes in TypeScript

A

Allow for creating objects with defined properties and methods, supporting OOP principles.

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

Enums

A

Define a set of named constants, making code more readable.

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

Generics

A

Enable writing reusable and type-safe code components.

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

Union Types

A

Allow variables to hold more than one type, e.g., string | number.

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

Type Aliases

A

Provide a way to name and reuse custom types.

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

Literal Types

A

Restrict a variable to specific values, e.g., let direction: ‘up’ | ‘down’.

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

Type Inference

A

TypeScript can infer variable types based on assigned values.

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

Any Type

A

A type that disables type checking, useful in dynamic code.

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

Never Type

A

Indicates values that never occur, e.g., in unreachable code.

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

Void Type

A

Used for functions that don’t return a value.

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

Tuple

A

An array with fixed types and length.

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

Type Assertion

A

Tell the compiler to treat a value as a specific type using as or <>.

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

Optional Parameters

A

Functions can define optional parameters with the ? syntax.

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

Readonly Modifier

A

Prevents reassignment of properties or variables.

21
Q

Access Modifiers

A

Keywords like public, private, and protected control property access.

22
Q

Default Parameters

A

Functions can have parameters with default values.

23
Q

Decorators

A

Special annotations used to modify classes or methods at runtime.

24
Q

Namespaces

A

Used to organize and group related code.

25
Q

Modules

A

Allow splitting code into reusable files and importing/exporting between them.

26
Q

TypeScript Compiler

A

The tsc command compiles TypeScript to JavaScript.

27
Q

Configuration File

A

tsconfig.json configures TypeScript compiler options.

28
Q

Strict Mode

A

Enabled in tsconfig.json to enforce strict typing rules.

29
Q

Declaration Files

A

Files with a .d.ts extension provide type definitions for JavaScript libraries.

30
Q

Mapped Types

A

Transform properties in a type, e.g., making them optional.

31
Q

Intersection Types

A

Combine multiple types into one using &.

32
Q

Keyof Operator

A

Get all keys of a type as a union.

33
Q

Indexed Access Types

A

Access the type of a property in an object type.

34
Q

Utility Types

A

Predefined types like Partial, Readonly, Record, etc., for common transformations.

35
Q

Type Guards

A

Runtime checks to ensure a variable matches a specific type.

36
Q

Abstract Classes

A

Classes that cannot be instantiated but can be extended.

37
Q

Promises in TypeScript

A

Handle asynchronous operations with typed Promises.

38
Q

Error Handling

A

Use try-catch blocks with type-safe error objects.

39
Q

Compatibility with JS

A

TypeScript is fully compatible with existing JavaScript code.

40
Q

DOM Manipulation

A

Type-safe interaction with HTML elements using TypeScript.

41
Q

Function Overloading

A

Define multiple function signatures for one implementation.

42
Q

Constructor

A

Special method in classes for initializing objects.

43
Q

Static Members

A

Class-level properties or methods shared across all instances.

44
Q

TypeScript Playground

A

Online editor to experiment with TypeScript code.

45
Q

Tooling Support

A

Integrated into many IDEs like VS Code for autocompletion and type checking.

46
Q

Code Refactoring

A

Simplified and safer refactoring with static type checking.

47
Q

Community Support

A

Growing community and resources for TypeScript developers.

48
Q

Migration

A

Easily migrate JavaScript projects incrementally to TypeScript.