D. Prototype assignment must be inside declare global block
Solution
Step 1: Check module context requirement for global augmentation
Global augmentation requires the file to be a module, so it needs an export {} or import statement.
Step 2: Identify missing export statement
The code lacks export {}, so TypeScript treats it as a script, causing errors with declare global.
Final Answer:
Missing export {} to make file a module -> Option B
Quick Check:
File must be a module for declare global [OK]
Hint: Add 'export {}' to enable global augmentation [OK]
Common Mistakes:
Forgetting to make file a module
Trying to assign prototype inside declare global
Renaming methods unnecessarily
5. You want to add a global method logInfo() to the console object that prefixes messages with '[INFO]'. Which is the correct way to augment the global Console interface and implement this method?
hard
A. export {};
declare global {
interface Console {
logInfo(message: string): void;
}
}
console.logInfo = (msg) => console.log(`[INFO] ${msg}`);