当我构建这个项目时,我的项目不会让我通过:
Type error: Type 'string | string[]' is not assignable to type 'string[]'.
Type 'string' is not assignable to type 'string[]'.
12 | const items = products({
13 | where: {
> 14 | slugIn: productSlug,
| ^
15 | },
16 | }).nodes我知道这是一个ESLint on GraphQL,我如何设置我的ESLint让它通过这个部分?
我的.eslintrc
{
"extends": ["plugin:storybook/recommended", "next", "next/core-web-vitals", "eslint:recommended"],
"globals": {
"React": "readonly",
"JSX": "readonly"
},
"rules": {
"no-unused-vars": [
1,
{
"args": "after-used",
"argsIgnorePattern": "^_",
"react/react-in-jsx-scope": "off"
}
]
},
"overrides": [{
"files": ["*.stories.@(ts|tsx|js|jsx|mjs|cjs)"],
"rules": {
"storybook/hierarchy-separator": "error"
}
}]
}发布于 2022-06-19 06:15:36
抱歉,不是什么问题,是代码错误。
看起来productSlug是字符串\ string[]之间的一个联合类型,slugIn接受一个字符串数组,即string[]。要传递输入错误,可以将第14行替换为类似于slugIn: Array.isArray(productSlug)的内容?productSlug : productSlug
变化
const items = products({
where: {
slugIn: productSlug,
},
}).nodes至
const items = products({
where: {
slugIn: Array.isArray(productSlug) ? productSlug : [productSlug],
},
}).nodeshttps://stackoverflow.com/questions/72658728
复制相似问题