简体   繁体   English

输入'字符串[] | undefined' 不可分配给类型 'string | 不明确的'

[英]Type 'string[] | undefined' is not assignable to type 'string | undefined'

I am new to typescript. I am facing some while declaring Props in typescript as follows:我是typescript的新手,在typescript中声明Props时遇到了一些如下:

Types of property 'd' are incompatible.
Type 'string[] | undefined' is not assignable to type 'string | undefined'.

I have one xyzProps which contains some sting type and one is string[] as given below:我有一个 xyzProps,其中包含一些 sting 类型,一个是 string[],如下所示:

const d1: string[] = [];

type xyzProps = {
  a: string;
  b: string;
  c: string;
  d: typeof d1;
};

When I am trying to use the above propes as follows then it gives an error当我尝试按如下方式使用上述属性时,它会出错

export type abcPageProps = RouteComponentProps<Partial<xyzProps>> & ReduxProps;

Any idea why it gives me this error OR any solution for it.知道为什么它会给我这个错误或任何解决方案。

can you try你能试一下吗

type xyzProps = {
   a: string;
   b: string;
   c: string;
   d: string[];
};

export type abcPageProps = RouteComponentProps<xyzProps> & ReduxProps;

暂无
暂无

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

相关问题 类型“字符串”不可分配给类型“未定义” - Type 'string' is not assignable to type ' undefined' 键入'字符串 | undefined' 不可分配给类型 'string' - Type 'string | undefined' is not assignable to type 'string' 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 类型 { [key: string]: string } 不可分配给类型 { [key: string]: string } | '不明确的' - Type { [key: string]: string } is not assignable to type { [key: string]: string } | 'undefined' 键入'字符串 | 号码 | boolean' 不能分配给类型 'undefined'。 类型“字符串”不可分配给类型“未定义”.ts(2322) - Type 'string | number | boolean' is not assignable to type 'undefined'. Type 'string' is not assignable to type 'undefined'.ts(2322) 'string | 类型的参数 undefined' 不能分配给'string' 类型的参数。 typescript '严格' - Argument of type 'string | undefined' is not assignable to parameter of type 'string'. typescript 'strict' 输入&#39;字符串| null&#39; 不能分配给类型 &#39;string | TypeScript 的未定义错误 - Type 'string | null' is not assignable to type 'string | undefined error with TypeScript 'string | 类型的参数 undefined' 不可分配给“string”类型的参数 - TypeScript 错误 - Argument of type 'string | undefined' is not assignable to parameter of type 'string' - TypeScript error Typescript:类型参数'string | undefined' 不能分配给“string”类型的参数 - Typescript: Argument of type 'string | undefined' is not assignable to parameter of type 'string' 参数类型编号不可分配给参数类型字符串 | 未定义类型编号不可分配给类型字符串 - Argument type number is not assignable to parameter type string | undefined Type number is not assignable to type string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM