【发布时间】:2021-07-20 12:19:45
【问题描述】:
Typescript 无法检测到我的全局 gtag var。
我安装了@types/gtag.js。这是它的index.d.ts 文件:
node_modules/@types/gtag.js/index.d.ts
这是我得到的错误:
所以我将此添加到我的.eslintrc.js
globals: {
gtag: typeof gtag // IT DOES DETECT THE gtag TYPE HERE
},
现在我只收到这个错误:
找不到名称“gtag”。
这是我的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"
]
}
如何让 Typescript 检测到声明的 gtag 全局变量?
【问题讨论】:
标签: typescript tsconfig gtag.js .d.ts