File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import type { Exact , OptionalParameter } from "./util" ;
2
+
3
+ type Assignable < LHS , RHS > = [ RHS ] extends [ LHS ] ? true : false ;
4
+
5
+ type OptionalInput = {
6
+ key ?: string ;
7
+ optional ?: string ;
8
+ } ;
9
+
10
+ type RequiredInput = {
11
+ key : string | undefined ;
12
+ optional ?: string ;
13
+ } ;
14
+
15
+ {
16
+ // optional parameter transform of an optional input is not equivalent to exactly 1 parameter.
17
+ type A = [ ...OptionalParameter < OptionalInput > ] ;
18
+ type B = [ OptionalInput ] ;
19
+ type C = [ OptionalInput ] | [ ] ;
20
+
21
+ const assert1 : Exact < A , B > = false as const ;
22
+ const assert2 : Exact < A , C > = true as const ;
23
+
24
+ const assert3 : Assignable < A , [ ] > = true as const ;
25
+ const assert4 : A = [ ] ;
26
+
27
+ const assert5 : Assignable < A , [ { key : "" } ] > = true as const ;
28
+ const assert6 : A = [ { key : "" } ] ;
29
+ }
30
+
31
+ {
32
+ // optional parameter transform of a required input is equivalent to exactly 1 parameter.
33
+ type A = [ ...OptionalParameter < RequiredInput > ] ;
34
+ type B = [ RequiredInput ] ;
35
+
36
+ const assert1 : Exact < A , B > = true as const ;
37
+ const assert2 : Assignable < A , [ ] > = false as const ;
38
+ const assert3 : Assignable < A , [ { key : "" } ] > = true as const ;
39
+ const assert4 : A = [ { key : "" } ] ;
40
+ }
You can’t perform that action at this time.
0 commit comments