const changeToInvalidations = (change: Change): Array<Invalidation> => {
switch (change.resourceType) {
case "brand":
switch (change.type) {
case "added":
return [{ type: "page", value: "productListing" }]
case "updated":
return [{ type: "brand", value: change.resourceId }]
case "removed":
return [{ type: "brand", value: change.resourceId }]
}
case "product":
switch (change.type) {
case "added":
return [{ type: "page", value: "productListing" }]
case "updated":
return [{ type: "product", value: change.resourceId }]
case "removed":
return [
{ type: "page", value: "productListing" }, // pagination reflow
{ type: "brand", value: change.resourceId },
]
}
}
}
Change
类型的定义:TypeScript开关盒彻底检查不起作用?
type Change = {
type: "added" | "updated" | "removed"
resourceId: number
resourceType: "brand" | "product"
}
错误:
Function lacks ending return statement and return type does not include 'undefined'
但是从阅读本https://www.typescriptlang.org/docs/handbook/advanced-types.html
看来我应该是好去。我做错了什么?
如何定义Change? – Saravana
@Saravana我用它的定义更新了描述。希望能帮助到你! –
可能与[this discussion](https://github.com/Microsoft/TypeScript/issues/8618)有关。 – Saravana