首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Next.js设置GraphQL .eslintrc

Next.js设置GraphQL .eslintrc
EN

Stack Overflow用户
提问于 2022-06-17 11:30:58
回答 1查看 41关注 0票数 -1

当我构建这个项目时,我的项目不会让我通过:

代码语言:javascript
复制
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

代码语言:javascript
复制
{
    "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"
        }
    }]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-19 06:15:36

抱歉,不是什么问题,是代码错误。

看起来productSlug是字符串\ string[]之间的一个联合类型,slugIn接受一个字符串数组,即string[]。要传递输入错误,可以将第14行替换为类似于slugIn: Array.isArray(productSlug)的内容?productSlug : productSlug

变化

代码语言:javascript
复制
const items = products({
  where: {
    slugIn: productSlug,
 },
}).nodes

代码语言:javascript
复制
const items = products({
    where: {
        slugIn: Array.isArray(productSlug) ? productSlug : [productSlug],
    },
}).nodes
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72658728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档