Typescript is not being able to detect my global gtag
var.
I have the @types/gtag.js
installed. Here is its index.d.ts
file:
node_modules/@types/gtag.js/index.d.ts
This is the error I was getting:
So I added this to my .eslintrc.js
globals: {
gtag: typeof gtag // IT DOES DETECT THE gtag TYPE HERE
},
Now I'm getting only this error:
Cannot find name 'gtag'.
Here is my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"types": [
"node"
],
"baseUrl": ".",
"paths": {
"@app/*": [
"./app/*"
],
"@lib/*": [
"./lib/*"
]
},
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
What can I do to make Typescript detect the declared gtag
global variable?
My problem was related to the
types
property on thetsconfig.json
tsconfig.json
Once I've removed those lines, the global
gtag
type was detected.From https://www.typescriptlang.org/tsconfig#types