TypeScript Expert

1 / 53

What is transpilation?

Select the correct answer

1

Transpilation is the process of converting TypeScript code to JavaScript code.

2

Transpilation is the process of debugging TypeScript code.

3

Transpilation is the process of minifying JavaScript code.

4

Transpilation is the process of bundling multiple JavaScript files into one.

What is a generic type in TypeScript?

Select the correct answer

1

A generic type in TypeScript is a type that can only be a string or number.

2

A generic type in TypeScript is used for error handling.

3

A generic type in TypeScript is used to define specific types of variables.

4

A generic type in TypeScript allows a type to be a parameter when defining classes, interfaces, and functions.

What are triple-slash directives?

Select the correct answer

1

Triple-slash directives in TypeScript are comments that contain a single XML tag used to provide additional information to the compiler.

2

Triple-slash directives in TypeScript are used for defining types.

3

Triple-slash directives in TypeScript are comments for declaring global variables.

4

Triple-slash directives in TypeScript are used to handle errors.

What is an abstract class in TypeScript, and how is it different from a regular class?

Select the correct answer

1

An abstract class in TypeScript is a class that cannot be instantiated and is meant to be subclassed.

2

An abstract class in TypeScript is a class that cannot extend other classes.

3

An abstract class in TypeScript is a class that has only static methods.

4

An abstract class in TypeScript is used for defining interfaces.

Explain "module resolution" in TypeScript.

Select the correct answer

1

Module resolution in TypeScript is the process of managing state.

2

Module resolution in TypeScript is the process of handling async operations.

3

Module resolution in TypeScript is the process of defining module types.

4

Module resolution in TypeScript is the process the compiler uses to find the actual location of modules.

Explain the symbol type in TypeScript.

Select the correct answer

1

The symbol type in TypeScript is used for string manipulation.

2

The symbol type in TypeScript is used for defining arrays.

3

The symbol type in TypeScript is a primitive data type that represents a unique identifier.

4

The symbol type in TypeScript is a data type for storing numbers.

What is the difference between extends and implements in TypeScript?

Select the correct answer

1

The extends keyword in TypeScript is used for variable declaration, whereas implements is used for function declarations.

2

The extends keyword in TypeScript is used for function overloading, whereas implements is used for type assertions.

3

The extends keyword in TypeScript is used for creating arrays, whereas implements is used for object creation.

4

The extends keyword in TypeScript is used for class inheritance, whereas implements is used to implement interfaces.

What are namespaces in TypeScript?

Select the correct answer

1

Namespaces in TypeScript are used to organize code into logical groups and prevent name collisions.

2

Namespaces in TypeScript are used to define new types.

3

Namespaces in TypeScript are used for error handling.

4

Namespaces in TypeScript are used to create modules.

Name the two primary types of modules in TypeScript?

Select the correct answer

1

The two primary types of modules in TypeScript are global modules and local modules.

2

The two primary types of modules in TypeScript are ES6 modules and CommonJS modules.

3

The two primary types of modules in TypeScript are synchronous modules and asynchronous modules.

4

The two primary types of modules in TypeScript are class modules and function modules.

Explain modules in TypeScript.

Select the correct answer

1

Modules in TypeScript are used to organize code into reusable pieces.

2

Modules in TypeScript are used to define types.

3

Modules in TypeScript are a way to declare variables.

4

Modules in TypeScript are used for error handling.

What is an anonymous function in TypeScript?

Select the correct answer

1

An anonymous function in TypeScript is a function with a static keyword.

2

An anonymous function in TypeScript is a function that returns a boolean.

3

An anonymous function in TypeScript is a function that does not have a name.

4

An anonymous function in TypeScript is a function declared with the var keyword.

Explain the as const assertion in TypeScript.

Select the correct answer

1

The as const assertion in TypeScript ensures that the type of a value is a literal type.

2

The as const assertion in TypeScript makes a variable immutable.

3

The as const assertion in TypeScript converts a type to any.

4

The as const assertion in TypeScript is used to declare constants.

Explain the concept of "declaration files" in TypeScript.

Select the correct answer

1

Declaration files in TypeScript provide type information about JavaScript libraries to TypeScript.

2

Declaration files in TypeScript are a way to define custom types.

3

Declaration files in TypeScript are used to configure the TypeScript compiler.

4

Declaration files in TypeScript are used for managing project dependencies.

Explain the purpose of the "key remapping" feature in mapped types in TypeScript.

Select the correct answer

1

Key remapping in mapped types in TypeScript is a method for importing modules.

2

Key remapping in mapped types in TypeScript is a feature for handling asynchronous operations.

3

Key remapping in mapped types in TypeScript is used to define optional properties.

4

Key remapping in mapped types in TypeScript allows the keys of a type to be transformed during the creation of a new type.

What is the purpose of "string literal types" in TypeScript?

Select the correct answer

1

String literal types in TypeScript are used to define string arrays.

2

String literal types in TypeScript are used to define enum values.

3

String literal types in TypeScript are types that can hold any string value.

4

String literal types in TypeScript are types whose value is a specific string.

What is "type-safe nullish coalescing" in TypeScript?

Select the correct answer

1

Type-safe nullish coalescing in TypeScript ensures that null or undefined values are handled safely.

2

Type-safe nullish coalescing in TypeScript is used for strict null checks.

3

Type-safe nullish coalescing in TypeScript is a method for error handling.

4

Type-safe nullish coalescing in TypeScript converts all null values to empty strings.

What is meant by contextual typing?

Select the correct answer

1

Contextual typing in TypeScript is a feature for importing modules.

2

Contextual typing in TypeScript is used to handle asynchronous programming.

3

Contextual typing in TypeScript is the process of defining custom types.

4

Contextual typing in TypeScript is the process by which the compiler infers types based on the context of the code.

What is the Omit utility type in TypeScript?

Select the correct answer

1

The Omit utility type in TypeScript is used to define arrays.

2

The Omit utility type in TypeScript converts a type into a union type.

3

The Omit utility type in TypeScript makes all properties of a type optional.

4

The Omit utility type in TypeScript constructs a type by excluding certain properties from another type.

What is the Partial utility type in TypeScript?

Select the correct answer

1

The Partial utility type in TypeScript removes all properties of a type.

2

The Partial utility type in TypeScript is used to define arrays.

3

The Partial utility type in TypeScript converts a type into a union type.

4

The Partial utility type in TypeScript makes all properties of a type optional.

What is the purpose of the unknown type in TypeScript?

Select the correct answer

1

The unknown type in TypeScript represents a value that could be of any type but is more type-safe than any.

2

The unknown type in TypeScript is used for variables that are null or undefined.

3

The unknown type in TypeScript is used for defining constants.

4

The unknown type in TypeScript is used exclusively for arrays.

What is the purpose of noImplicitAny?

Select the correct answer

1

The noImplicitAny flag in TypeScript ensures that all variables have an explicit type.

2

The noImplicitAny flag in TypeScript allows the use of any type without errors.

3

The noImplicitAny flag in TypeScript is used to enable strict null checks.

4

The noImplicitAny flag in TypeScript allows implicit casting between types.

Explain the purpose of type predicates in TypeScript.

Select the correct answer

1

Type predicates in TypeScript are functions that return a boolean indicating the type of a variable.

2

Type predicates in TypeScript are used to declare types.

3

Type predicates in TypeScript are methods for importing modules.

4

Type predicates in TypeScript are tools for debugging.

Explain the concept of "recursive types" in TypeScript.

Select the correct answer

1

Recursive types in TypeScript are types that can be null or undefined.

2

Recursive types in TypeScript are types used for async functions.

3

Recursive types in TypeScript are types that inherit from other types.

4

Recursive types in TypeScript are types that reference themselves.

What is the "non-nullable assertion operator" (!) in TypeScript?

Select the correct answer

1

The non-nullable assertion operator (!) in TypeScript is used for creating loops.

2

The non-nullable assertion operator (!) in TypeScript is used to declare constants.

3

The non-nullable assertion operator (!) in TypeScript tells the compiler that a value is not null or undefined.

4

The non-nullable assertion operator (!) in TypeScript is used to import modules.

Explain the concept of discriminated unions in TypeScript.

Select the correct answer

1

Discriminated unions in TypeScript are used to handle errors.

2

Discriminated unions in TypeScript are used for asynchronous programming.

3

Discriminated unions in TypeScript are used to define enums.

4

Discriminated unions in TypeScript are unions with a common property used to distinguish between them.

What are distributive conditional types?

Select the correct answer

1

Distributive conditional types in TypeScript are used for module imports.

2

Distributive conditional types in TypeScript are a type of error handling.

3

Distributive conditional types in TypeScript are used to define array types.

4

Distributive conditional types in TypeScript distribute a conditional type over a union type.

What are "conditional types" in TypeScript?

Select the correct answer

1

Conditional types in TypeScript are used to create optional parameters.

2

Conditional types in TypeScript allow for type selection based on a condition.

3

Conditional types in TypeScript are used to define enums.

4

Conditional types in TypeScript are a type of error handling.

What is the purpose of keyof in TypeScript

Select the correct answer

1

The keyof keyword in TypeScript is used to import modules.

2

The keyof keyword in TypeScript is used to declare dynamic properties.

3

The keyof keyword in TypeScript is used to create new types.

4

The keyof keyword in TypeScript is used to get the keys of an object type.

What are mixins?

Select the correct answer

1

Mixins in TypeScript are a way to create reusable code by combining multiple classes.

2

Mixins in TypeScript are used to style components.

3

Mixins in TypeScript are a way to manage state.

4

Mixins in TypeScript are a type of module import.

What is optional chaining in TypeScript?

Select the correct answer

1

Optional chaining in TypeScript allows for the safe access of nested object properties.

2

Optional chaining in TypeScript is used to create optional function parameters.

3

Optional chaining in TypeScript is a method for error handling.

4

Optional chaining in TypeScript is used to declare optional variables.

What is void, and when to use the void type?

Select the correct answer

1

Void in TypeScript represents a type that can be anything.

2

Void in TypeScript represents the absence of a return value from a function.

3

Void in TypeScript represents a null value.

4

Void in TypeScript is used for error handling.

How does TypeScript handle asynchronous programming?

Select the correct answer

1

TypeScript handles asynchronous programming with a special async keyword.

2

TypeScript handles asynchronous programming with promises, async/await syntax, and observables.

3

TypeScript handles asynchronous programming with only callback functions.

4

TypeScript handles asynchronous programming by automatically converting all functions to async.

What are mapped types in TypeScript?

Select the correct answer

1

Mapped types in TypeScript are used to configure the TypeScript compiler.

2

Mapped types in TypeScript are used to manage project dependencies.

3

Mapped types in TypeScript are used for mapping URLs to components.

4

Mapped types in TypeScript create new types by transforming properties.

What are intersection types in TypeScript, and how do they differ from union types?

Select the correct answer

1

Intersection types in TypeScript combine multiple types into one.

2

Intersection types in TypeScript are used to define numeric arrays.

3

Intersection types in TypeScript are used for asynchronous programming.

4

Intersection types in TypeScript are used to create read-only properties.

What is a union type in TypeScript?

Select the correct answer

1

A union type in TypeScript is a special type for handling numbers and strings together.

2

A union type in TypeScript is used for combining multiple interfaces.

3

A union type in TypeScript allows a variable to be one of several types.

4

A union type in TypeScript is a method for error handling.

What is the null and undefined type in TypeScript?

Select the correct answer

1

In TypeScript, null and undefined are types that represent zero and empty string.

2

In TypeScript, null and undefined are types that represent boolean values.

3

In TypeScript, null and undefined are types used for error handling.

4

In TypeScript, null and undefined are types that represent the absence of a value.

What is strict mode in TypeScript?

Select the correct answer

1

Strict mode in TypeScript is a set of type-checking options that ensure more robust code.

2

Strict mode in TypeScript enables runtime type checking.

3

Strict mode in TypeScript is used for optimizing code performance.

4

Strict mode in TypeScript is used to enforce strict naming conventions.

What is an enum in TypeScript.

Select the correct answer

1

An enum in TypeScript is a syntax for creating classes.

2

An enum in TypeScript is used to define environment variables.

3

An enum in TypeScript is a data type for storing arrays.

4

An enum in TypeScript is a way of defining named constants.

Explain the never type in TypeScript.

Select the correct answer

1

The never type in TypeScript is used for declaring global variables.

2

The never type in TypeScript represents a type that can be anything.

3

The never type in TypeScript represents null and undefined values.

4

The never type in TypeScript represents values that never occur.

Explain what tuples are TypeScript.

Select the correct answer

1

Tuples in TypeScript are classes with multiple inheritance.

2

Tuples in TypeScript are functions that return multiple values.

3

Tuples in TypeScript are objects with dynamic properties.

4

Tuples in TypeScript are arrays with a fixed number of elements of specified types.

How can a class constant be implemented in TypeScript?

Select the correct answer

1

A class constant can be implemented using the private keyword in TypeScript.

2

A class constant can be implemented using the const keyword in TypeScript.

3

A class constant can be implemented using the static keyword in TypeScript.

4

A class constant can be implemented using the readonly keyword in TypeScript.

What is a type guard in TypeScript, and how does it help narrow down types?

Select the correct answer

1

A type guard is a debugging tool in TypeScript.

2

A type guard is a function that determines if a variable is of a specific type, helping to narrow down types in TypeScript.

3

A type guard is used to secure TypeScript applications from hacking.

4

A type guard is a syntax error detector in TypeScript.

Explain the difference between interface and type alias in TypeScript.

Select the correct answer

1

Interfaces are used for styling components, and type aliases are used for database connections.

2

Interfaces are used for managing state, and type aliases are used for routing.

3

Interfaces are used for creating instances, and type aliases are used for importing modules.

4

Interfaces define a contract for a structure, whereas type aliases can define primitive types, union types, and tuples.

What are TypeScript decorators?

Select the correct answer

1

TypeScript decorators are used to configure the TypeScript compiler.

2

TypeScript decorators are used to style components.

3

TypeScript decorators are used to create private methods.

4

TypeScript decorators are special types of declarations that can be attached to a class, method, accessor, property, or parameter.

What is the as keyword used for in TypeScript?

Select the correct answer

1

The as keyword is used to create asynchronous functions.

2

The as keyword is used for type assertions in TypeScript.

3

The as keyword is used to declare static variables.

4

The as keyword is used to import modules.

What is the any type in TypeScript, and when should you use it?

Select the correct answer

1

The any type in TypeScript is used exclusively for numbers.

2

The any type in TypeScript is used for functions returning strings.

3

The any type in TypeScript is used to declare arrays only.

4

The any type in TypeScript is used when you want to disable type checking for a variable.

Explain what type inference is in TypeScript.

Select the correct answer

1

Type inference is a feature to suggest variable names in TypeScript.

2

Type inference is the act of debugging type errors in TypeScript.

3

Type inference is the process of converting JavaScript to TypeScript.

4

Type inference is the ability of the TypeScript compiler to automatically deduce types.

Can TypeScript be used for the backend?

Select the correct answer

1

Yes, TypeScript can be used for backend development using Node.js.

2

No, TypeScript is only for frontend development.

3

No, TypeScript does not support backend features.

4

Yes, but it requires a special compiler.

What is TSX?

Select the correct answer

1

TSX is a type of stylesheet used in TypeScript.

2

TSX stands for TypeScript XML and is used for embedding XML in TypeScript.

3

TSX is a database query language for TypeScript.

4

TSX is a testing framework for TypeScript applications.

What is the use of the tsconfig.json file?

Select the correct answer

1

It is used to configure TypeScript compiler options.

2

It is used to define environment variables for Node.js.

3

It is used to manage project dependencies.

4

It is used to set up a testing framework.

Name the access modifiers supported in TypeScript.

Select the correct answer

1

protected, private, static, and final.

2

public, private, default, and static.

3

public, protected, default, and final.

4

public, private, protected, and readonly.

Define static typing.

Select the correct answer

1

A method of overloading functions in JavaScript.

2

A system where variables are checked at runtime.

3

A type system where types are checked at compile time.

4

A typing system used exclusively for dynamic languages.

What is TypeScript?

Select the correct answer

1

A database management system.

2

A strongly typed superset of JavaScript that compiles to plain JavaScript.

3

A framework for building mobile applications.

4

A library for managing state in React applications.