Problem Statement
Demonstrate declaration merging to augment a third-party library’s types safely.
Explanation
Add a .d.ts file that reopens the module with declare module and extends its interfaces. This avoids editing node_modules and survives package upgrades.
Code Solution
SolutionRead Only
/* types/my-lib-augment.d.ts */
declare module 'my-lib' {
interface Widget { version: string }
export function makeWidgetWithVersion(v: string): Widget;
}
// Usage
import { makeWidgetWithVersion } from 'my-lib';
const w = makeWidgetWithVersion('1.2.3');
w.version.toUpperCase();