Your code is technically correct, and works in the TypeScript playground, which leads me to believe that the problem is being caused by having this code inside of a module.
When you write an interface within a module, or namespace, it contributes to the naming context of that module or namespace. i.e. you may well be adding a new interface named String
to your local naming context, rather than merging your interface declaration with the global String
interface.
You can fix this by placing your interface in the global context, so it has the same common root as the one from the lib.d.ts
file. Or using declare global
from within a module:
declare global {
interface String {
transl(): string;
}
}
String.prototype.transl = function () {
return 'xxx';
};
'ff'.transl();