I am encountering a perplexing error code TS2339: Property 'X' is not found on type 'Y'. How can I resolve this issue?
I have included libraries in my 'tsconfig.jsonc' file:
"compilerOptions": {
"target": "es3", // "es3" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"watch": true,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"esnext",
"es2018",
"es2017",
"es2016",
"es2015",
"es7",
"es6",
"es5",
"dom",
"dom.iterable",
"ScriptHost"
] /* Specify library files to be included in the compilation. */,
...
}
The following code snippet
const userName: string = groupAddress.replace('@gmail.com', '')
is throwing an error
Property 'replace' does not exist on type 'string'.
In a similar manner,
const addMembers = (email: string, studio: string, role): void => {
const memberKey = email.trim()
results in
Property 'trim' does not exist on type 'string'.
const groupKeys: string[] = [
`report.${name}@gmail.com`,
`support.${name}@gmail.com`
]
groupKeys.forEach((groupKey: string) => {
if (!GroupsApp.getGroupByEmail(groupKey).hasUser(memberKey)) {
AdminDirectory.Members.insert({ email: memberKey, role }, groupKey)
}
})
yields
Property 'forEach' does not exist on type '{}'.
I anticipate
- the method 'replace' belonging to type string, and
- the method 'forEach' belonging to type string[].
However, typescript claims otherwise.