Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript:Property';价值';不存在于类型';字符串{value:string;label:string;}';_Typescript - Fatal编程技术网

Typescript:Property';价值';不存在于类型';字符串{value:string;label:string;}';

Typescript:Property';价值';不存在于类型';字符串{value:string;label:string;}';,typescript,Typescript,得到这个错误 Property 'value' does not exist on type 'string | { value: string; label: string; }'. 当我们有这个OR运算符时,它应该能够取任何值,对吗?因此,如果值是string,那么它应该很好,不是吗?添加更多上下文:什么代码证明了这个错误。此|运算符使您能够将对象设置为某物或其他某物。鉴于此,如果您使用myObject作为字符串执行console.log(myObject.value)。那么这是正常的:)

得到这个错误

Property 'value' does not exist on type 'string | { value: string; label: string; }'.

当我们有这个OR运算符时,它应该能够取任何值,对吗?因此,如果值是string,那么它应该很好,不是吗?

添加更多上下文:什么代码证明了这个错误。此|运算符使您能够将对象设置为某物或其他某物。鉴于此,如果您使用myObject作为字符串执行console.log(myObject.value)。那么这是正常的:)