-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.test.js
66 lines (52 loc) · 1.65 KB
/
index.test.js
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
60
61
62
63
64
65
66
/* @flow */
import type { Arguments } from '..'
(() => {
type Fn0 = () => void
type Fn1 = (?string) => void
type Fn2 = (string, number) => void
type Fn3 = (string, string, string) => void
const fn = () => undefined
;(([]): Arguments<Fn0>)
/**
* $ExpectError
* Cannot cast array literal to `Arguments` because number [1] is incompatible with string [2] in the first argument.
*/
;(([1]): Arguments<Fn1>)
;(([undefined]): Arguments<Fn1>)
;((['x']): Arguments<Fn1>)
;((['a', 1]): Arguments<Fn2>)
/**
* $ExpectError
* Cannot cast array literal to `Arguments` because string [1] is incompatible with number [2] in the second argument.
*/
;((['a', 'x']): Arguments<Fn2>)
;((['a', 'a', 'a']): Arguments<Fn3>)
/**
* $ExpectError
* Cannot cast array literal to `Arguments` because number [1] is incompatible with string [2] in index 2.
*/
;((['a', 'a', 3]): Arguments<Fn3>)
;((['a', 1]): Arguments<Fn2>)
;(([]): Arguments<Fn0>)
/**
* $ExpectError
* Cannot cast array literal to `Arguments` because rest array [1] has an arity of 1 but tuple type [2] has an arity of 0.
*/
;(([1]): Arguments<Fn0>)
;(([]): Arguments<typeof fn>)
/**
* $ExpectError
* Cannot cast array literal to `Arguments` because rest array [1] has an arity of 1 but tuple type [2] has an arity of 0.
*/
;(([1]): Arguments<Fn0>)
})()
;(() => {
const fn3 = (a: string, b: number, c: string): string => c
declare var y: (...args: Arguments<typeof fn3>) => void;
y('x', 1, 'x')
/**
* $ExpectError
* Cannot call `y` because number [1] is incompatible with string [2] in the third argument.
*/
y('x', 1, 1)
})()