TypeScript Fundamentals Flashcards

What is TypeScript? tsconfig.json Basic types (string, number, boolean) let, const, and variable declarations Type annotations and inference Basic compilation and CLI usage (48 cards)

1
Q

What is TypeScript?

A

TypeScript is a strongly typed superset of JavaScript that compiles to plain JavaScript.

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

What is the purpose of tsconfig.json?

A

tsconfig.json is a configuration file that specifies the root files and compiler options required to compile a TypeScript project.

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

What are basic types in TypeScript?

A

Basic types include string, number, boolean, null, undefined, void, and any.

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

What is the difference between let and const in TypeScript?

A

let allows reassignment of variables, while const creates read-only references that cannot be reassigned.

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

What is type annotation in TypeScript?

A

Type annotation is the explicit declaration of a variable’s type, e.g., let age: number = 25;

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

What is type inference in TypeScript?

A

TypeScript automatically infers the type of a variable based on its assigned value if no annotation is provided.

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

How do you compile TypeScript code?

A

Use the command ‘tsc’ (TypeScript Compiler) in the terminal to compile .ts files to .js files.

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

What is the CLI command to initialize a TypeScript project?

A

tsc –init creates a tsconfig.json file with default configuration settings.

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

What are the advantages of using TypeScript?

A

Improved code quality, better tooling support, early bug detection, and enhanced developer productivity.

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

What are the disadvantages of TypeScript?

A

Steeper learning curve, longer setup time, and sometimes verbose syntax compared to plain JavaScript.

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

What is a best practice when using TypeScript types?

A

Prefer explicit type annotations for function parameters and return types to improve readability and type safety.

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

What is a common use case for TypeScript?

A

Large-scale applications where strong typing and IDE support can significantly improve maintainability and refactoring.

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

How does TypeScript impact system design?

A

It enforces contracts via types, improving modularity, code correctness, and long-term maintainability of large systems.

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

What is an example of using a string type?

A

let name: string = ‘Alice’;

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

What is an architectural implication of using TypeScript?

A

TypeScript encourages cleaner module boundaries and makes refactoring safer across large codebases.

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

How does TypeScript affect performance?

A

TypeScript adds no runtime overhead since it compiles to JavaScript; performance is mostly unaffected.

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

Can TypeScript help with fault tolerance?

A

Yes, TypeScript helps catch type-related errors at compile-time, reducing runtime failures.

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

What is a debugging benefit of TypeScript?

A

TypeScript’s strict typing and error messages help identify issues earlier in the development cycle.

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

What’s a real-world tradeoff of using TypeScript?

A

You gain safer, maintainable code at the cost of additional complexity and a compile step in your build process.

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

What’s a common interview question about TypeScript?

A

What are the differences between TypeScript and JavaScript, and when would you use TypeScript?

21
Q

What is a potential gotcha with type inference?

A

If the inferred type is too broad (like ‘any’), it can silently allow bugs that strict typing would have caught.

22
Q

What does ‘strict’ mode in tsconfig.json do?

A

It enables all strict type-checking options, making the compiler more rigorous and reducing bugs.

23
Q

What’s the difference between ‘any’ and ‘unknown’?

A

‘any’ disables type checking, while ‘unknown’ is safer and forces type checking before usage.

24
Q

What happens if you omit a variable’s type in TypeScript?

A

The compiler infers the type from the value assigned, or uses ‘any’ if there’s no context.

25
What’s the benefit of using const for variables?
const ensures that variables cannot be reassigned, making code more predictable and reducing bugs.
26
What is a common pitfall when using 'any'?
Using 'any' too frequently defeats the purpose of TypeScript and can lead to runtime errors.
27
Why is type inference useful?
It allows cleaner code while still benefiting from type checking where the compiler can determine the type.
28
What is a basic example of a function with type annotations?
function greet(name: string): string { return `Hello, ${name}`; }
29
What’s a best practice for organizing tsconfig.json?
Use extends for shared base config, and override specifics in individual projects or packages.
30
How does tsconfig.json help with project scalability?
It centralizes compiler settings, enabling consistent builds and easier configuration across large codebases.
31
What are composite projects in tsconfig.json?
Composite projects support project references, enabling faster builds and modular monorepo structures.
32
What’s a potential issue with using JavaScript libraries in TypeScript?
If type definitions aren’t available, you may need to install @types packages or manually define them.
33
What is the use of 'include' and 'exclude' in tsconfig.json?
They define which files should be compiled or ignored by the TypeScript compiler.
34
What’s the role of 'outDir' in tsconfig.json?
It specifies the output directory for compiled JavaScript files.
35
What’s a best practice for variable declarations?
Use const by default, let when reassignment is necessary, and avoid var altogether.
36
What does the TypeScript compiler do?
It checks type correctness and converts TypeScript code into JavaScript code.
37
What’s a potential gotcha with using 'const'?
'const' prevents reassignment, but the values inside objects or arrays declared with const can still be mutated.
38
Can you use JavaScript files in a TypeScript project?
Yes, by enabling 'allowJs' in tsconfig.json, but you lose type safety unless you add annotations or JSDoc.
39
What’s a good way to transition from JavaScript to TypeScript?
Start by renaming .js files to .ts and gradually add types and stricter compiler settings.
40
What is an example of number type usage?
let age: number = 30;
41
What is the default type if you don’t specify or assign a value?
The type defaults to 'any', which disables type checking.
42
What’s the purpose of 'noImplicitAny' in tsconfig.json?
It prevents variables from implicitly having the 'any' type, forcing explicit typing or inference.
43
How can you enable stricter type checking across a project?
Set 'strict': true in tsconfig.json to enable all strict mode checks.
44
What’s the tradeoff of using strict mode?
It increases safety and code clarity but may require more boilerplate and upfront type definitions.
45
Why is it important to avoid the 'any' type?
It disables type checking and can lead to runtime errors, negating the benefits of TypeScript.
46
What’s a common interview question about tsconfig.json?
What are some important compiler options in tsconfig.json and how do they impact your build process?
47
What is the TypeScript compiler CLI command for a single file?
tsc filename.ts
48
What is the benefit of static typing in large codebases?
It enables better tooling, easier refactoring, and earlier error detection.