Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit c0d8219

Browse files
committed
Removed type property
Creation was not possible and we can achieve the same thing with "crit" in props. See also microsoft/TypeScript#12052
1 parent bb306a7 commit c0d8219

File tree

6 files changed

+16
-48
lines changed

6 files changed

+16
-48
lines changed

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { Popup, Rarity, ItemType } from './item';
1+
export { Popup, Rarity } from './item';
22
export { Group as ModGroup, Type as ModType } from './mod';

src/item/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { default as Popup } from './popup';
2-
export { Rarity, Type as ItemType } from './poe';
2+
export { Rarity} from './poe';

src/item/poe.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { SingleValue, Value, AugmentableValue } from '../util/value';
55

66
// use intersection here instead of extends to be able to test Properties
77
// with only e.g. ArmourProperties
8-
export type Item = AbstractItem &
9-
(ArmourProperties | WeaponProperties | NoProperties);
8+
export type Item = AbstractItem & Properties;
109

1110
export interface AbstractItem {
1211
base: BaseItem;
@@ -24,18 +23,13 @@ export interface AbstractItem {
2423
shaper?: boolean;
2524
}
2625

27-
export enum Type {
28-
none,
29-
armour,
30-
weapon,
31-
}
26+
export type Properties = ShieldProperties | ArmourProperties | WeaponProperties | NoProperties;
3227

3328
export interface AbstractProperties {
3429
quality?: number;
3530
}
3631

3732
export interface ArmourProperties extends AbstractProperties {
38-
type: Type.armour;
3933
armour?: AugmentableValue<SingleValue>;
4034
energy_shield?: AugmentableValue<SingleValue>;
4135
evasion?: AugmentableValue<SingleValue>;
@@ -47,7 +41,6 @@ export interface ShieldProperties extends ArmourProperties {
4741
}
4842

4943
export interface WeaponProperties extends AbstractProperties {
50-
type: Type.weapon;
5144
physical_damage?: AugmentableValue;
5245
cold_damage?: Value;
5346
fire_damage?: Value;
@@ -66,9 +59,7 @@ export interface WeaponProperties extends AbstractProperties {
6659
crit?: AugmentableValue<SingleValue>;
6760
}
6861

69-
export interface NoProperties extends AbstractProperties {
70-
type?: Type.none;
71-
}
62+
export interface NoProperties extends AbstractProperties {}
7263

7364
export interface BaseItem {
7465
name: string;

src/item/popup/body/Properties.tsx

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ArmourProperties,
88
NoProperties,
99
ShieldProperties,
10-
Type,
1110
} from '../../poe';
1211
import { round, msToPerSecond, asPercentString } from '../../../util/number';
1312
import {
@@ -30,26 +29,18 @@ export default class Properties extends React.PureComponent<Props> {
3029
return true;
3130
}
3231

33-
switch (properties.type) {
34-
case Type.armour:
35-
const { armour, energy_shield, evasion } = properties;
32+
if ("armour" in properties) {
33+
const { armour, energy_shield, evasion } = properties;
3634
return (
3735
augmentableNotZero(armour) ||
3836
augmentableNotZero(energy_shield) ||
3937
augmentableNotZero(evasion)
4038
);
41-
case Type.weapon:
39+
} else if ("aps" in properties) {
4240
// at least display weapon type
4341
return true;
44-
case Type.none:
45-
case undefined:
46-
return false;
47-
default:
48-
// while the exhaustiveness check is nice for internal use
49-
// it's not guarenteed at runtime since this component can be consumed
50-
// by normal js
51-
// @ts-ignore
52-
throw new Error(`unrecognized property kind '${properties.kind}'`);
42+
} else {
43+
return false;
5344
}
5445
}
5546

@@ -73,22 +64,10 @@ export default class Properties extends React.PureComponent<Props> {
7364
);
7465
}
7566

76-
switch (properties.type) {
77-
case Type.armour:
78-
display_properties.push(...this.armourProperties(properties));
79-
break;
80-
case Type.weapon:
81-
display_properties.push(...this.weaponProperties(properties));
82-
break;
83-
case Type.none:
84-
case undefined:
85-
break;
86-
default:
87-
// while the exhaustiveness check is nice for internal use
88-
// it's not guarenteed at runtime since this component can be consumed
89-
// by normal js
90-
// @ts-ignore
91-
throw new Error(`unrecognized property kind '${properties.kind}'`);
67+
if ("armour" in properties) {
68+
display_properties.push(...this.armourProperties(properties));
69+
} else if ("aps" in properties) {
70+
display_properties.push(...this.weaponProperties(properties));
9271
}
9372

9473
return display_properties;

stories/docs/helmet.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { storiesOf } from '@storybook/react';
33
import { withInfo } from '@storybook/addon-info';
44
import { formatStats } from 'poe-i18n';
55
// 'poe-components-item'
6-
import { Popup, Rarity, ModType, ItemType } from '../../src/';
6+
import { Popup, Rarity, ModType } from '../../src/';
77

88
import '../../themes/poe.scss';
99

@@ -22,7 +22,6 @@ storiesOf('ItemPopup', module).add(
2222
name: 'Hubris Circlet',
2323
},
2424
name: 'Mind Brow',
25-
type: ItemType.armour,
2625
rarity: Rarity.rare,
2726
energy_shield: {
2827
value: 200,

stories/docs/i18n.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { storiesOf } from '@storybook/react';
33
import { formatStats, Fallback } from 'poe-i18n';
44
// 'poe-components-item'
5-
import { Popup, Rarity, ModType, ItemType } from '../../src/';
5+
import { Popup, Rarity, ModType } from '../../src/';
66

77
const base_item_types = require('poe-i18n/locale-data/en/BaseItemTypes.json');
88
const stat_descriptions = require('poe-i18n/locale-data/en/stat_descriptions.json');
@@ -39,7 +39,6 @@ storiesOf('i18n integration', module).add('Helmet', () => (
3939
name: base_item_types['1768'].name,
4040
},
4141
name: 'Mind Brow',
42-
type: ItemType.armour,
4342
rarity: Rarity.rare,
4443
energy_shield: {
4544
value: 200,

0 commit comments

Comments
 (0)