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)
What is TypeScript?
TypeScript is a strongly typed superset of JavaScript that compiles to plain JavaScript.
What is the purpose of tsconfig.json?
tsconfig.json is a configuration file that specifies the root files and compiler options required to compile a TypeScript project.
What are basic types in TypeScript?
Basic types include string, number, boolean, null, undefined, void, and any.
What is the difference between let and const in TypeScript?
let allows reassignment of variables, while const creates read-only references that cannot be reassigned.
What is type annotation in TypeScript?
Type annotation is the explicit declaration of a variable’s type, e.g., let age: number = 25;
What is type inference in TypeScript?
TypeScript automatically infers the type of a variable based on its assigned value if no annotation is provided.
How do you compile TypeScript code?
Use the command ‘tsc’ (TypeScript Compiler) in the terminal to compile .ts files to .js files.
What is the CLI command to initialize a TypeScript project?
tsc –init creates a tsconfig.json file with default configuration settings.
What are the advantages of using TypeScript?
Improved code quality, better tooling support, early bug detection, and enhanced developer productivity.
What are the disadvantages of TypeScript?
Steeper learning curve, longer setup time, and sometimes verbose syntax compared to plain JavaScript.
What is a best practice when using TypeScript types?
Prefer explicit type annotations for function parameters and return types to improve readability and type safety.
What is a common use case for TypeScript?
Large-scale applications where strong typing and IDE support can significantly improve maintainability and refactoring.
How does TypeScript impact system design?
It enforces contracts via types, improving modularity, code correctness, and long-term maintainability of large systems.
What is an example of using a string type?
let name: string = ‘Alice’;
What is an architectural implication of using TypeScript?
TypeScript encourages cleaner module boundaries and makes refactoring safer across large codebases.
How does TypeScript affect performance?
TypeScript adds no runtime overhead since it compiles to JavaScript; performance is mostly unaffected.
Can TypeScript help with fault tolerance?
Yes, TypeScript helps catch type-related errors at compile-time, reducing runtime failures.
What is a debugging benefit of TypeScript?
TypeScript’s strict typing and error messages help identify issues earlier in the development cycle.
What’s a real-world tradeoff of using TypeScript?
You gain safer, maintainable code at the cost of additional complexity and a compile step in your build process.
What’s a common interview question about TypeScript?
What are the differences between TypeScript and JavaScript, and when would you use TypeScript?
What is a potential gotcha with type inference?
If the inferred type is too broad (like ‘any’), it can silently allow bugs that strict typing would have caught.
What does ‘strict’ mode in tsconfig.json do?
It enables all strict type-checking options, making the compiler more rigorous and reducing bugs.
What’s the difference between ‘any’ and ‘unknown’?
‘any’ disables type checking, while ‘unknown’ is safer and forces type checking before usage.
What happens if you omit a variable’s type in TypeScript?
The compiler infers the type from the value assigned, or uses ‘any’ if there’s no context.