It seems like your code is correct as it works in the TypeScript playground. However, the issue may arise from having the code within a module.
When you define an interface inside a module or namespace, it becomes part of that specific naming context. This means that you might unintentionally create a new interface with the same name as a global one, instead of merging them together.
To resolve this, consider placing your interface in the global scope to align it with the lib.d.ts
declaration. Alternatively, you can use declare global
within a module as shown below:
declare global {
interface String {
transform(): string;
}
}
String.prototype.transform = function () {
return 'yyy';
};
'abc'.transform();