Closed sunpm closed 3 months ago
不是可以类型里面声明一个全局的变量吗,就像window
不是可以类型里面声明一个全局的变量吗,就像window
是的,如果使用tsconfig不会有这个问题,但是用的是js…
你可以自己配置。我不用小程序,没有兴趣支持
给后来者提供一点帮助,可以这样配置以支持全局key:
const antfu = require('@antfu/eslint-config').default
const { FlatCompat } = require('@eslint/eslintrc')
const compat = new FlatCompat()
module.exports = antfu({
// your config
},
...compat.config({
globals: {
wx: 'readonly', // 微信小程序
uni: 'readonly', // uniapp
},
}))
FlatCompat 的配置看你的项目是ES的还是Common的,我这个给的是common的,ES的直接把require换成import就好了
Clear and concise description of the problem
小程序编译后会全局注入 uni、wx 等变量,可以保证它们一定存在。 但是开发过程中没有注入,导致 eslint 检测报错。 原来
.eslintrc.js中
可以配置 globals,配置到eslint.config.js
出现异常:Error: Key "globals": This appears to be in eslintrc format rather than flat config format.
Suggested solution
可否在 eslint config 中增加 globals 配置属性
Alternative
No response
Additional context
No response
Validations