Typescript Flashcards
What is TypeScript?
TypeScript is a superset of JavaScript that adds static typing.
True or False: TypeScript can compile to plain JavaScript.
True
Fill in the blank: TypeScript uses ____ to define the type of a variable.
annotations
What command is used to install TypeScript globally?
npm install -g typescript
What is the purpose of the ‘tsconfig.json’ file?
It configures the TypeScript compiler options for a project.
Multiple Choice: Which of the following is a primitive type in TypeScript? A) string B) Array C) Object
A) string
What does the ‘any’ type in TypeScript represent?
It represents any value and disables type checking.
True or False: TypeScript supports interfaces.
True
What is an interface in TypeScript?
An interface defines the structure of an object, specifying properties and methods.
Fill in the blank: In TypeScript, ____ can be used to define a function signature.
function types
What is the difference between ‘interface’ and ‘type’ in TypeScript?
‘interface’ can be extended while ‘type’ cannot.
Multiple Choice: Which keyword is used to create a class in TypeScript? A) create B) class C) function
B) class
True or False: TypeScript supports decorators.
True
What is a tuple in TypeScript?
A tuple is an array with a fixed number of elements with known types.
Fill in the blank: TypeScript’s ____ feature allows for optional properties in an object.
optional chaining
What is the use of the ‘readonly’ modifier in TypeScript?
It makes a property immutable after its initial assignment.
Multiple Choice: What symbol is used for defining a union type in TypeScript? A) & B) | C) ?
B) |
True or False: TypeScript can infer types automatically.
True
What is a namespace in TypeScript?
A namespace is a way to encapsulate related code to avoid name collisions.
Fill in the blank: You can use the ____ keyword to define a generic type in TypeScript.
generic
What is the purpose of the ‘never’ type in TypeScript?
It indicates a value that never occurs, such as in a function that throws an error.
Multiple Choice: Which of the following is NOT a TypeScript built-in type? A) string B) number C) void D) character
D) character
True or False: TypeScript can be used with React.
True
What is the purpose of the ‘as’ keyword in TypeScript?
It is used for type assertions to tell the compiler to treat a variable as a specified type.
Fill in the blank: TypeScript supports ____ types, which allow defining a variable that can have multiple types.
union
What does the ‘strict’ option in ‘tsconfig.json’ enable?
It enables all strict type-checking options.
Multiple Choice: How do you declare a variable with a specific type in TypeScript? A) var x: number B) let x = number C) x: number
A) var x: number
True or False: TypeScript allows the use of JavaScript libraries without type definitions.
True