Edit: This is an ESlint problem. I've included my ESLint setup at the end of this post.
I'm fairly new to TypeScript -- I have been refactoring someone else's React code, moving it to TypeScript for a work project when I ran into this line
const memoryOptionsResponse = window.webchatMethods.getMemory(chatId);
TypeScript complains about 'window.webchat', saying
Property 'X' does not exist on 'Window & typeof globalThis
After some googling, the answer would seem to be to put this at the root level of the module
declare global {
interface Window {
webchatMethods:any;
}
}
However now TS complains with the following error.
This Stack Overflow page suggests something similar, but again it has declare global
and ESLint balks.
After half an hour trying to fix this, I've decided to turn to you for advice -- if anyone knows a good solution, I'd appreciate it!
// .eslintconfig
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true
}
},
"extends": [
"eslint:recommended",
"prettier",
"plugin:react/recommended"
],
"plugins": [
"prettier",
"react",
"react-hooks"
],
"env": {
"es6": true,
"node": true,
"mocha": true,
"browser": true
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": 1,
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/no-unescaped-entities": "warn",
"react/no-find-dom-node": 0,
"comma-dangle": ["error", "never"],
"global-require": 0
}
}
// .eslintignore
test
node_modules