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)。那么这是正常的:)