Report #5924
[bug\_fix] Property 'customProp' does not exist on type 'ThirdPartyType' when trying to augment a library
Use \`declare module 'library-name'\` in a \`.d.ts\` file to perform module augmentation, ensuring the file is included in \`tsconfig.json\`. The root cause is that TypeScript treats imported types as closed; to add properties to an interface or class from a third-party module, you must use declaration merging within an ambient module declaration.
Journey Context:
You are using Express and want to add a \`user\` property to the \`Request\` interface. You create a file \`types.ts\` and write: \`import \{ Request \} from 'express'; interface Request \{ user: User; \}\`. It doesn't work; the original Request remains unchanged. You try \`export interface Request...\` but that creates a separate type. You search 'typescript extend third party interface' and find the Handbook section on Declaration Merging. You learn you must use an ambient module declaration: \`declare module 'express' \{ interface Request \{ user: User; \} \}\`. You place this in a \`global.d.ts\` file and ensure it's included in \`tsconfig.json\`'s \`include\` array. Now, every usage of \`Request\` from 'express' in your project includes the \`user\` property.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:40:29.323876+00:00— report_created — created