简体   繁体   English

类型错误:类型为“{ projectId: string | 不明确的; }' 不可分配给 'SCL| 类型的参数防雷器 | 不明确的'

[英]Type error: Argument of type '{ projectId: string | undefined; }' is not assignable to parameter of type 'SCL| SPD | undefined'

I'm trying to deploy my project to Vercel but it seems to be giving me this error saying the following:我正在尝试将我的项目部署到 Vercel,但它似乎给我这个错误,说明以下内容:

Type error: Argument of type '{ dataset: string;类型错误:类型为“{ dataset: string; 的参数” projectId: string |项目编号:字符串 | undefined;不明确的; apiVersion: string; api版本:字符串; useCdn: boolean;使用CDN:boolean; }' is not assignable to parameter of type 'SanityClientLike | }' 不可分配给 'SanityClientLike | 类型的参数SanityProjectDetails | SanityProject详情 | undefined'.不明确的'。 Type '{ dataset: string;输入'{数据集:字符串; projectId: string |项目编号:字符串 | undefined;不明确的; apiVersion: string; api版本:字符串; useCdn: boolean;使用CDN:boolean; }' is not assignable to type 'SanityProjectDetails'. }' 不可分配给类型 'SanityProjectDetails'。 Types of property 'projectId' are incompatible.属性“projectId”的类型不兼容。 Type 'string |输入'字符串| undefined' is not assignable to type 'string'. undefined' 不可分配给类型 'string'。
Type 'undefined' is not assignable to type 'string'.类型“undefined”不可分配给类型“string”。

import { createClient } from "next-sanity";
import createImageUrlBuilder from '@sanity/image-url';

export const config = {
    dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
    projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
    apiVersion: '2021-03-25',
    useCdn: process.env.NODE_ENV === 'production',
};

export const sanityClient = createClient(config);

export const urlFor = (source: any) => createImageUrlBuilder(config).image(source);

It's saying the error lies within the line createImageUrlBuilder(config).它说错误在于 createImageUrlBuilder(config) 行。 I'm not sure on what is wrong with this line.我不确定这条线有什么问题。 If anyone knows how to fix this, I will appreaciate it so much.如果有人知道如何解决这个问题,我会非常感激。

In your config add an OR condition with empty string value for projectId在您的配置中为 projectId 添加一个空字符串值的 OR 条件

export const config = {
    dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
    projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || '',
    apiVersion: '2021-03-25',
    useCdn: process.env.NODE_ENV === 'production',
};

You must put OR condition after projectId您必须在 projectId 之后放置 OR 条件

import { createClient } from "next-sanity";

import createImageUrlBuilder from "@sanity/image-url";

export const config = {
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || "",
  apiVersion: "2021-03-25",
  useCdn: process.env.NODE_ENV === "production",
};

export const sanityClient = createClient(config);

export const urlFor = (source: any) => {
  createImageUrlBuilder(config).image(source);
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'string | 类型的参数 undefined' 不能分配给'string' 类型的参数。 类型“未定义”不可分配给类型“字符串” - Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string' TS2345:“字符串”类型的参数 | undefined&#39; 不能分配给类型为 &#39;string&#39; 的参数。 “未定义”类型不能分配给“字符串”类型 - TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string' 'string | 类型的参数 undefined' 不可分配给“RequestInfo”类型的参数 - Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo' 如何使用 typescript 修复字符串类型的错误参数或未定义的参数不可分配给字符串类型的参数并做出反应? - How to fix the error argument of type string or undefined is not assignable to parameter of type string using typescript and react? 如何修复未定义类型的错误参数不可分配给'字符串或()=&gt;字符串类型的参数使用typescript并做出反应? - How to fix error argument of type undefined is not assignable to parameter of type 'string or () => string usng typescript and react? 类型“字符串”不可分配给类型“未定义” - Type 'string' is not assignable to type 'undefined' 类型“字符串”不可分配给类型“未定义” - Type 'string' is not assignable to type ' undefined' “void”类型的参数不能分配给“SetStateAction”类型的参数不明确的&#39; - Argument of type 'void' is not assignable to parameter of type 'SetStateAction | undefined' TypeScript(Nodejs 错误) 输入 'string | undefined' 不可分配给类型 'string'。 类型“undefined”不可分配给类型“string” - TypeScript(Nodejs error) Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string “number[]”类型的参数不可分配给“SetStateAction”类型的参数<ICoord | undefined> &#39; - Argument of type 'number[]' is not assignable to parameter of type 'SetStateAction<ICoord | undefined>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM