Unit 6 - Practice Quiz
1 Which TypeScript feature allows you to create a reusable component or function that works with a variety of types rather than a single one?
2
In TypeScript, what is the primary difference between an interface and a type alias regarding declaration merging?
3
Which TypeScript Utility Type constructs a type with all properties of Type T set to optional?
Required<T>
Pick<T, K>
Partial<T>
Omit<T, K>
4
When defining the type for a React Functional Component's props, which syntax is generally preferred for explicit typing without using the React.FC type?
function MyComponent(props: any) { ... }
function MyComponent({ name }: { name: string }) { ... }
const MyComponent = (props) => { ... }
function MyComponent<T>(props: T) { ... }
5
What is the purpose of the unknown type in TypeScript?
any.
null or undefined.
6 In the context of API typing, what is a Data Transfer Object (DTO)?
7
Which tsconfig.json compiler option enables a wide range of type checking behavior that results in stronger guarantees of program correctness?
"allowJs": true
"strict": true
"target": "ES6"
"module": "commonjs"
8 What is the main benefit of using Static Code Analysis tools like ESLint in a frontend project?
9
Given the following type definition, what is Status?
typescript
type Status = "loading" | "success" | "error";
10
When typing a useRef hook for an HTML Input element in React, which syntax is correct?
const inputRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const inputRef = useRef<HTMLElement>(null);
const inputRef = useRef(null);
11 What is the purpose of Source Maps in a web development debugging workflow?
12 Which of the following is a key characteristic of Unit Testing?
13 Which mathematical operator is used to create an Intersection Type in TypeScript?
|
&
+
*
14 In the context of Code Quality, what does the DRY principle stand for?
15
How can you type the event object in a React onChange handler for an input field?
event: Event
event: React.ChangeEvent<HTMLInputElement>
event: HTMLElement
event: any
16
What is the result of using the Omit<T, K> utility type?
K from T.
T and then removing K.
T readonly.
T and type K.
17 Which tool is commonly used to enforce code formatting styles (indentation, quotes, semicolons) automatically?
18 In a TypeScript project, what file extension is required for files that contain JSX syntax?
.ts
.js
.jsx
.tsx
19 What is Cyclomatic Complexity?
20 Which TypeScript configuration option allows importing JavaScript files into a TypeScript project during migration?
"allowJs": true
"checkJs": true
"noEmit": true
"jsx": "react"
21 What is Mocking in the context of unit testing?
22
Which generic constraint syntax ensures that a generic type T must contain a specific property length?
function fn<T extends { length: number }>(arg: T)
function fn<T implements { length: number }>(arg: T)
function fn<T : { length: number }>(arg: T)
function fn<T>(arg: T.length)
23 What is the primary purpose of Husky in a web development environment?
24 In React Testing Library, what is the best practice for selecting elements to test?
.container).
#submit-btn).
getByRole, getByText).
25 What is the definition of Technical Debt?
node_modules folder.
26 Which type of test verifies that the system meets external requirements and achieves its goals, usually testing the entire application stack?
27 Which TypeScript feature allows you to tell the compiler "I know this variable is type X, trust me"?
as syntax)
28
What is the result of accessing a property on a variable typed as any?
null.
29 Which SOLID principle suggests that a class (or module/function) should have one, and only one, reason to change?
30 What is the benefit of using Discriminated Unions in TypeScript for state management (e.g., Redux actions or loading states)?
31 In the browser console, which method displays data as an interactive table?
console.log()
console.error()
console.table()
console.dir()
32 How do you define an optional property in a TypeScript interface?
name: string?
name?: string
optional name: string
name: string | optional
33 Which of the following describes Regression Testing?
34
What is the purpose of the ReturnType<Type> utility in TypeScript?
35 When refactoring code, what is the primary goal?
36
Which TypeScript syntax allows a value to be one of several types (e.g., string OR number)?
string & number
string | number
string, number
[string, number]
37
In a tsconfig.json, what does "noImplicitAny": true do?
any types to string.
any type.
any types from the code.
38 What is a Snapshot Test in Jest?
39
When debugging, what does the Step Over command do?
40
What is the strict TypeScript type for children in a React component if you expect only React elements (not text or numbers)?
React.ReactNode
React.ReactElement
JSX.Element
any
41 What is Code Coverage?
42 Which TS utility type would you use to create a type where keys are strings and values are numbers?
Map<string, number>
Record<string, number>
Object<string, number>
Array<number>
43
What is the primary purpose of .d.ts files?
44 In the context of Clean Code, what does it mean to avoid Magic Numbers?
45 Which keyword is used to conditionally select types in TypeScript (often called generic conditional types)?
if
switch
extends (ternary syntax)
typeof
46 Which of the following creates a read-only array in TypeScript?
const arr = [1, 2, 3]
readonly number[] or ReadonlyArray<number>
final number[]
static number[]
47 What is the "Arrange-Act-Assert" pattern used for?
48 Which TypeScript operator checks if a property exists on an object and acts as a type guard?
exists
in
has
contains
49
How does useEffect dependency array typing help in development?
50 What is the mathematical definition of Big O Notation in the context of code quality?