我不太明白为什么以下does not compile:
interface IPreciousMetal {
type: "Silver" | "Gold"
}
interface ICryptoCurrency {
type: "Bitcoin" | "Litecoin"
}
type Asset = ICryptoCurrency | IPreciousMetal;
function process(assetType: Asset["type"]) {
const asset = { type: assetType };
processImpl(asset); // Error
}
function processImpl(asset: Asset) {
console.log(asset.type);
}
为参数assetType
传递的参数必须被键入以使其与Asset
类型兼容。但是,当使用上述参数值创建对象时,编译器会抱怨。