-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.spec.ts
45 lines (34 loc) · 1.11 KB
/
solution.spec.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
38
39
40
41
42
43
44
45
import type { Equal, Expect } from 'type-testing'
import { createStreetLight } from './solution'
describe('Challenge 18: prevent infer of the second argument and only allowing the literal types of the first argument', () => {
const colors = ['red' as const, 'yellow' as const, 'green' as const]
type Color = (typeof colors)[number]
it('Test 01', () => {
const fnReturn = createStreetLight(colors, 'red')
type Actual = typeof fnReturn
type Expected = 'red' | 'yellow' | 'green'
type Test = Expect<Equal<Actual, Expected>>
})
it('Test 02', () => {
const fnReturn = createStreetLight<Color>(colors, 'red')
type Actual = typeof fnReturn
type Expected = 'red' | 'yellow' | 'green'
type Test = Expect<Equal<Actual, Expected>>
})
it('Test 03', () => {
// @ts-expect-error
createStreetLight(colors, 'blue')
})
it('Test 04', () => {
// @ts-expect-error
createStreetLight<Color, 'red'>(colors, 'red')
})
it('Test 05', () => {
// @ts-expect-error
createStreetLight<Color, 'blue'>(colors, 'blue')
})
it('Test 06', () => {
// @ts-expect-error
createStreetLight<Color>(colors, 'blue')
})
})