Skip to content

Commit 73aee9e

Browse files
authored
Merge pull request #12 from abraham/empty-classes-are-bad
Fix empty classes acting as any
2 parents ecb9e10 + c695b5c commit 73aee9e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ import { Failure, fold, Initialized, Pending, Success } from './index';
22

33
test('Initialized', () => {
44
expect(new Initialized()).toBeInstanceOf(Initialized);
5+
expect(new Initialized().kind).toEqual('Initialized');
56
});
67

78
test('Pending', () => {
89
expect(new Pending()).toBeInstanceOf(Pending);
10+
expect(new Pending().kind).toEqual('Pending');
911
});
1012

1113
test('Success', () => {
1214
const data = { apple: 'sauce' };
1315
const state = new Success(data);
1416
expect(state).toBeInstanceOf(Success);
17+
expect(state.kind).toEqual('Success');
1518
expect(state.data).toEqual(data);
1619
});
1720

@@ -23,6 +26,7 @@ test('Failure', () => {
2326
const error = 500;
2427
const state = new Failure(error);
2528
expect(state).toBeInstanceOf(Failure);
29+
expect(state.kind).toEqual('Failure');
2630
expect(state.error).toEqual(error);
2731
});
2832

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
export type RemoteData<D, E> = Initialized | Pending | Success<D> | Failure<E>;
22

3-
export class Initialized {}
3+
export class Initialized {
4+
private kind = 'Initialized';
5+
}
46

5-
export class Pending {}
7+
export class Pending {
8+
private kind = 'Pending';
9+
}
610

711
export class Success<D> {
12+
private kind = 'Success';
13+
814
constructor(public data: D) {
915
if (data === null || data === undefined) {
1016
fail('Parameter "data" is required');
@@ -13,6 +19,8 @@ export class Success<D> {
1319
}
1420

1521
export class Failure<E> {
22+
private kind = 'Failure';
23+
1624
constructor(public error: E) {
1725
if (error === null || error === undefined) {
1826
fail('Parameter "error" is required');

0 commit comments

Comments
 (0)