I want to add a new method to String.prototype. I tried this.
interface String {
newMethod(): void
}
String.prototype.newMethod = function() {}
No errors in typescriptlang.org playground. But still show me a error Property 'newMethod' does not exist on type 'String' in my local computer.
I don't know why.
Here is my tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
}
}
I install `@types/node
I found some example.
// example1: no error
interface String {
newMethod(): void
}
String.prototype.newMethod = function() {}
// example2: has error
import * as path from 'path'
interface String {
newMethod(): void
}
String.prototype.newMethod = function() {}
Only import statement added, error occured. So strange. I don't know why?