-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathissue-115.ts
37 lines (31 loc) · 1.11 KB
/
issue-115.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as assert from 'assert';
import { is } from '../index';
/* https://github.com/woutervh-/typescript-is/issues/115 */
export const Status = {
enable: 'enable',
disable: 'disable'
} as const;
type StatusObject<Key extends keyof typeof Status> = {
status: (typeof Status)[Key];
};
const testObj = {
outer: 0
};
describe('is', () => {
describe('Accessing generic member of a type', () => {
it('should return true for the right member', () => {
assert.deepStrictEqual(is<StatusObject<'enable'>>({ status: Status.enable }), true);
});
it('should return false for the wrong member', () => {
assert.deepStrictEqual(is<StatusObject<'enable'>>({ status: Status.disable }), false);
});
});
describe('Using typeof instead of a type', () => {
it('should return true for the right member', () => {
assert.deepStrictEqual(is<typeof testObj>('test'), false);
});
it('should return false for the wrong member', () => {
assert.deepStrictEqual(is<typeof testObj>({ outer: 5 }), true);
});
});
});