mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Refactor: use union type in ItemName type to implement Item interface
This commit is contained in:
parent
def709f2e1
commit
12e7f8e82e
@ -1,19 +1,22 @@
|
||||
import { AgedBrie, Passes, Surfras } from "./itemClasses";
|
||||
type ItemClasses = AgedBrie[] | Surfras[] | Passes[];
|
||||
import { Item } from "./itemClasses";
|
||||
|
||||
interface ItemForSale extends Item {
|
||||
handleQuality: () => void;
|
||||
handleSellIn: () => void;
|
||||
}
|
||||
|
||||
export class GildedRose {
|
||||
items: ItemClasses;
|
||||
constructor(items = [] as ItemClasses) {
|
||||
items: ItemForSale[];
|
||||
constructor(items = [] as ItemForSale[]) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
const updatedItems = this.items.map((item) => {
|
||||
return this.items.map((item) => {
|
||||
item.handleSellIn();
|
||||
item.handleQuality();
|
||||
|
||||
return item;
|
||||
});
|
||||
return updatedItems as ItemClasses;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
export class Item {
|
||||
name: string;
|
||||
sellIn: number;
|
||||
quality: number;
|
||||
export type ItemName =
|
||||
| "Aged Brie"
|
||||
| "Backstage passes to a TAFKAL80ETC concert"
|
||||
| "Conjured Mana Cake"
|
||||
| "Sulfuras, Hand of Ragnaros";
|
||||
|
||||
constructor(name, sellIn, quality) {
|
||||
export class Item {
|
||||
name;
|
||||
sellIn;
|
||||
quality;
|
||||
|
||||
constructor(name: ItemName, sellIn: number, quality: number) {
|
||||
this.name = name;
|
||||
this.sellIn = sellIn;
|
||||
this.quality = quality;
|
||||
|
||||
BIN
sql/structure/.DS_Store
vendored
Normal file
BIN
sql/structure/.DS_Store
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user