Created
December 20, 2023 08:06
-
-
Save Hayao0819/78aa1a4bda71bf9e0d58fee3a2b59466 to your computer and use it in GitHub Desktop.
ラーメン二郎の型定義
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type MenuAmount = "マシ" | "多め" | "マシマシ" | "かなり多め" | "普通" | "少なめ" | "無し"; | |
export type IsGarlicAdded = | |
| "全てマシ" | |
| "全て普通" | |
| "全て少なめ" | |
| { | |
ニンニク?: MenuAmount; | |
ヤサイ?: MenuAmount; | |
アブラ?: MenuAmount; | |
カラメ?: boolean; | |
}; | |
export class JirouRamen { | |
name: string; | |
orderInvalidErr = new Error("はぁ?"); | |
supportedAmount: MenuAmount[] = ["マシ", "多め", "普通", "少なめ", "無し"]; | |
constructor(name: string) { | |
this.name = name; | |
} | |
valicateOrder(order: IsGarlicAdded) { | |
if (order == "全てマシ") { | |
order = { | |
ニンニク: "マシ", | |
ヤサイ: "マシ", | |
アブラ: "マシ", | |
カラメ: true, | |
}; | |
} else if (order == "全て普通") { | |
order = { | |
ニンニク: "普通", | |
ヤサイ: "普通", | |
アブラ: "普通", | |
カラメ: false, | |
}; | |
} else if (order == "全て少なめ") { | |
order = { | |
ニンニク: "少なめ", | |
ヤサイ: "少なめ", | |
アブラ: "少なめ", | |
カラメ: false, | |
}; | |
} | |
if (order.ニンニク && !this.supportedAmount.includes(order.ニンニク)) { | |
throw this.orderInvalidErr; | |
} | |
if (order.ヤサイ && !this.supportedAmount.includes(order.ヤサイ)) { | |
throw this.orderInvalidErr; | |
} | |
if (order.アブラ && !this.supportedAmount.includes(order.アブラ)) { | |
throw this.orderInvalidErr; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment