-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.test-d.ts
59 lines (51 loc) · 1.84 KB
/
main.test-d.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable @typescript-eslint/naming-convention */
import { expectType, expectAssignable, expectNotAssignable } from 'tsd'
import { set, test, type Index, type Updates, type Options } from 'set-array'
expectType<never[]>(set([], {}))
expectType<string[]>(set(['a'], {}))
expectType<string[]>(set([], { 0: 'a' }))
expectType<string[]>(set([], { 0: ['a', 'b'] }))
expectType<(string | number)[]>(set(['a', 1], {}))
expectType<(string | number)[]>(set(['a', 1], { 0: ['a', 1] }))
set(['a'], {}, { merge: (a: string, b: string) => b })
set([], { '-0': 'a' })
set([], { '0+': 'a' })
set([], { '-12+': 'a' })
set([], { '*': 'a' })
// @ts-expect-error
set(true, {})
// @ts-expect-error
set([], true)
// @ts-expect-error
set([], {}, true)
// @ts-expect-error
set([], {}, { unknownOption: true })
// @ts-expect-error
set([], {}, { merge: true })
// @ts-expect-error
set(['a'], {}, { merge: (a: string, b: number) => b })
// @ts-expect-error
set(['a'], {}, { merge: (a: string, b: string) => true })
// @ts-expect-error
set([], { a: 'a' })
// @ts-expect-error
set([], { '--0': 'a' })
// @ts-expect-error
set([], { '0++': 'a' })
expectType<boolean>(test({}))
expectType<boolean>(test({ 0: 'a' }))
expectType<boolean>(test({ a: 'a' }))
expectType<boolean>(test([]))
expectAssignable<Index>('-12+')
expectAssignable<Index>('*')
expectNotAssignable<Index>('a')
expectAssignable<Updates<string>>({ '-12+': 'a' })
expectAssignable<Updates<string>>({ '*': 'a' })
expectAssignable<Updates<string>>({ '*': ['a'] })
expectAssignable<Updates<string>>({})
expectNotAssignable<Updates<string>>({ a: 'a' })
expectNotAssignable<Updates<string>>({ '*': true })
expectAssignable<Options<string>>({})
expectAssignable<Options<string>>({ merge: (a: string, b: string) => b })
expectNotAssignable<Options<string>>({ unknownOption: true })
/* eslint-enable @typescript-eslint/naming-convention */