diff --git a/src/index.tsx b/src/index.tsx index 67452c4..2a04a4a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,2 +1,2 @@ -export { Popup, Rarity, ItemType } from './item'; +export { Popup, Rarity } from './item'; export { Group as ModGroup, Type as ModType } from './mod'; diff --git a/src/item/index.ts b/src/item/index.ts index e8931e5..9338e89 100644 --- a/src/item/index.ts +++ b/src/item/index.ts @@ -1,2 +1,2 @@ export { default as Popup } from './popup'; -export { Rarity, Type as ItemType } from './poe'; +export { Rarity} from './poe'; diff --git a/src/item/poe.ts b/src/item/poe.ts index d64576c..028b91f 100644 --- a/src/item/poe.ts +++ b/src/item/poe.ts @@ -5,8 +5,7 @@ import { SingleValue, Value, AugmentableValue } from '../util/value'; // use intersection here instead of extends to be able to test Properties // with only e.g. ArmourProperties -export type Item = AbstractItem & - (ArmourProperties | WeaponProperties | NoProperties); +export type Item = AbstractItem & Properties; export interface AbstractItem { base: BaseItem; @@ -24,18 +23,13 @@ export interface AbstractItem { shaper?: boolean; } -export enum Type { - none, - armour, - weapon, -} +export type Properties = ShieldProperties | ArmourProperties | WeaponProperties | NoProperties; export interface AbstractProperties { quality?: number; } export interface ArmourProperties extends AbstractProperties { - type: Type.armour; armour?: AugmentableValue; energy_shield?: AugmentableValue; evasion?: AugmentableValue; @@ -47,7 +41,6 @@ export interface ShieldProperties extends ArmourProperties { } export interface WeaponProperties extends AbstractProperties { - type: Type.weapon; physical_damage?: AugmentableValue; cold_damage?: Value; fire_damage?: Value; @@ -66,9 +59,7 @@ export interface WeaponProperties extends AbstractProperties { crit?: AugmentableValue; } -export interface NoProperties extends AbstractProperties { - type?: Type.none; -} +export interface NoProperties extends AbstractProperties {} export interface BaseItem { name: string; diff --git a/src/item/popup/body/Properties.tsx b/src/item/popup/body/Properties.tsx index bd6584d..ad1b01c 100644 --- a/src/item/popup/body/Properties.tsx +++ b/src/item/popup/body/Properties.tsx @@ -7,7 +7,6 @@ import { ArmourProperties, NoProperties, ShieldProperties, - Type, } from '../../poe'; import { round, msToPerSecond, asPercentString } from '../../../util/number'; import { @@ -30,26 +29,18 @@ export default class Properties extends React.PureComponent { return true; } - switch (properties.type) { - case Type.armour: - const { armour, energy_shield, evasion } = properties; + if ("armour" in properties) { + const { armour, energy_shield, evasion } = properties; return ( augmentableNotZero(armour) || augmentableNotZero(energy_shield) || augmentableNotZero(evasion) ); - case Type.weapon: + } else if ("aps" in properties) { // at least display weapon type return true; - case Type.none: - case undefined: - return false; - default: - // while the exhaustiveness check is nice for internal use - // it's not guarenteed at runtime since this component can be consumed - // by normal js - // @ts-ignore - throw new Error(`unrecognized property kind '${properties.kind}'`); + } else { + return false; } } @@ -73,22 +64,10 @@ export default class Properties extends React.PureComponent { ); } - switch (properties.type) { - case Type.armour: - display_properties.push(...this.armourProperties(properties)); - break; - case Type.weapon: - display_properties.push(...this.weaponProperties(properties)); - break; - case Type.none: - case undefined: - break; - default: - // while the exhaustiveness check is nice for internal use - // it's not guarenteed at runtime since this component can be consumed - // by normal js - // @ts-ignore - throw new Error(`unrecognized property kind '${properties.kind}'`); + if ("armour" in properties) { + display_properties.push(...this.armourProperties(properties)); + } else if ("aps" in properties) { + display_properties.push(...this.weaponProperties(properties)); } return display_properties; diff --git a/stories/docs/helmet.tsx b/stories/docs/helmet.tsx index e06e499..fb9206e 100644 --- a/stories/docs/helmet.tsx +++ b/stories/docs/helmet.tsx @@ -3,7 +3,7 @@ import { storiesOf } from '@storybook/react'; import { withInfo } from '@storybook/addon-info'; import { formatStats } from 'poe-i18n'; // 'poe-components-item' -import { Popup, Rarity, ModType, ItemType } from '../../src/'; +import { Popup, Rarity, ModType } from '../../src/'; import '../../themes/poe.scss'; @@ -22,7 +22,6 @@ storiesOf('ItemPopup', module).add( name: 'Hubris Circlet', }, name: 'Mind Brow', - type: ItemType.armour, rarity: Rarity.rare, energy_shield: { value: 200, diff --git a/stories/docs/i18n.tsx b/stories/docs/i18n.tsx index c961ca3..5e7702d 100644 --- a/stories/docs/i18n.tsx +++ b/stories/docs/i18n.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { storiesOf } from '@storybook/react'; import { formatStats, Fallback } from 'poe-i18n'; // 'poe-components-item' -import { Popup, Rarity, ModType, ItemType } from '../../src/'; +import { Popup, Rarity, ModType } from '../../src/'; const base_item_types = require('poe-i18n/locale-data/en/BaseItemTypes.json'); const stat_descriptions = require('poe-i18n/locale-data/en/stat_descriptions.json'); @@ -39,7 +39,6 @@ storiesOf('i18n integration', module).add('Helmet', () => ( name: base_item_types['1768'].name, }, name: 'Mind Brow', - type: ItemType.armour, rarity: Rarity.rare, energy_shield: { value: 200,