I've googled around a bit but I can't find anything regarding this, might be because I'm not exactly sure what causing the issue.
I wanted to set a global value on the node.js global object. Just a simple string
global.appRoot = path.resolve(__dirname)
Since I'm using Typescript, my editor (Visual Studio Code) warned me that the property did not exist on type Global which makes sense.
I went ahead and created a global.d.ts in my root folder with
declare namespace NodeJS {
export interface Global {
appRoot: string;
}
}
This worked perfectly and the editor tells me it's fine, but still breaks on other random properties, so everything still works.
However, this is where the issue is. When i run the following to lint and fix my code it doesn't seem the recognize my declartion file global.d.ts and crashing with the same error message that VS Code gave me earlier. src/app.ts:15:8 - error TS2339: Property 'appRoot' does not exist on type 'Global & typeof globalThis'.
eslint -c ./.eslintrc.js --ext .ts,.js --fix ./src/**/*.{js,ts}`
These are my config files
.eslintrc.js
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
env: {
node: true,
},
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
...
},
};
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"moduleResolution": "node",
"baseUrl": "./src",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modues"
]
}