0
在打字稿2.1,嘗試時執行以下操作:JSX元素屬性類型[...]可能不是一個聯合類型
錯誤TS2600:在編譯時發生
// address.tsx ... interface Address { street: string; country: string; } interface CanadianAddress extends Address { postalCode: string; } interface AmericanAddress extends Address { zipCode: string; } type Properties = AmericanAddress | CanadianAddress' function isAmerican(address: Properties) address is AmericanAddress { return 'zipCode' in address; } export class Address extends React.Component<Properties, void> { public render() { let isAmerican = isAmerican(this.props.address); ... } } // map.tsx ... let rootDiv = document.createElement('root')l ReactDOM.render(<Address postalCode='T1B 0L3' />, rootDiv);
的跟隨誤差:JSX元素屬性類型'({children?:ReactNode;} & AmericanAddress)| ({孩子?: ReactNode;} & CanadianAddress'可能不是一個聯合類型
我想知道這是爲什麼不支持,我哪能做到這一點,而不必過於-組複雜的。 ?屬性來指定
https://github.com/Microsoft/TypeScript/issues/13526 –