Concerning your first error
TS2339 Build:Property 'contains' does not exist on type 'String'
make sure to extend the String
interface in the global scope, not in a module file. That means, there may not be any export
or import
at the file top-level.
interface String {
foo(): void
}
String.prototype.foo = () => { console.log("bar") }
"aksljflasd".foo()
Playground
You could also use declare global
in a module file:
export {}
declare global {
interface String {
foo(): void
}
}
"aksljflasd".foo()
Playground
Concerning second error
Property includes
does not exist on type 'string'
you need minimum ES6
for String.prototype.includes
. So it is likely, that you have target
of ES5
or lower in tsconfig.json
. Also, when you manually set lib
option, make sure to have ES2015.Core
included.
Playground