1
1
import { expectTypeOf } from 'expect-type' ;
2
+
3
+ // Intentionally checking the shape of the exports *and* the export itself.
2
4
import * as gc from '@glimmer/component' ;
5
+ // tslint:disable-next-line: no-duplicate-imports
6
+ import Component from '@glimmer/component' ;
3
7
4
8
// Imported from non-public-API so we can check that we are publishing what we
5
9
// expect to be -- and this keeps us honest about the fact that if we *change*
6
10
// this import location, we've broken any existing declarations published using
7
11
// the current type signatures.
8
12
import { EmptyObject } from '@glimmer/component/addon/-private/component' ;
9
13
10
- const Component = gc . default ;
14
+ declare let basicComponent : Component ;
15
+ expectTypeOf ( basicComponent ) . toHaveProperty ( 'args' ) ;
16
+ expectTypeOf ( basicComponent ) . toHaveProperty ( 'isDestroying' ) ;
17
+ expectTypeOf ( basicComponent ) . toHaveProperty ( 'isDestroyed' ) ;
18
+ expectTypeOf ( basicComponent ) . toHaveProperty ( 'willDestroy' ) ;
19
+ expectTypeOf ( basicComponent . isDestroying ) . toEqualTypeOf < boolean > ( ) ;
20
+ expectTypeOf ( basicComponent . isDestroyed ) . toEqualTypeOf < boolean > ( ) ;
21
+ expectTypeOf ( basicComponent . willDestroy ) . toEqualTypeOf < ( ) => void > ( ) ;
11
22
12
23
expectTypeOf ( gc ) . toHaveProperty ( 'default' ) ;
13
24
expectTypeOf ( gc . default ) . toEqualTypeOf < typeof Component > ( ) ;
14
25
15
- type Args = {
26
+ type LegacyArgs = {
16
27
foo : number ;
17
28
} ;
18
29
19
- const componentWithLegacyArgs = new Component < Args > ( { } , { foo : 123 } ) ;
20
- expectTypeOf ( componentWithLegacyArgs ) . toHaveProperty ( 'args' ) ;
21
- expectTypeOf ( componentWithLegacyArgs ) . toHaveProperty ( 'isDestroying' ) ;
22
- expectTypeOf ( componentWithLegacyArgs ) . toHaveProperty ( 'isDestroyed' ) ;
23
- expectTypeOf ( componentWithLegacyArgs ) . toHaveProperty ( 'willDestroy' ) ;
24
- expectTypeOf ( componentWithLegacyArgs . args ) . toEqualTypeOf < Readonly < Args > > ( ) ;
25
- expectTypeOf ( componentWithLegacyArgs . isDestroying ) . toEqualTypeOf < boolean > ( ) ;
26
- expectTypeOf ( componentWithLegacyArgs . isDestroyed ) . toEqualTypeOf < boolean > ( ) ;
27
- expectTypeOf ( componentWithLegacyArgs . willDestroy ) . toEqualTypeOf < ( ) => void > ( ) ;
30
+ const componentWithLegacyArgs = new Component < LegacyArgs > ( { } , { foo : 123 } ) ;
31
+ expectTypeOf ( componentWithLegacyArgs . args ) . toEqualTypeOf < Readonly < LegacyArgs > > ( ) ;
32
+
33
+ // Here, we are testing that the types propertly distribute over union types,
34
+ // generics which extend other types, etc.
35
+ // Here, we are testing that the types propertly distribute over union types,
36
+ // generics which extend other types, etc.
37
+ type LegacyArgsDistributive = { foo : number } | { bar : string ; baz : boolean } ;
38
+
39
+ const legacyArgsDistributiveA = new Component < LegacyArgsDistributive > ( { } , { foo : 123 } ) ;
40
+ expectTypeOf ( legacyArgsDistributiveA . args ) . toEqualTypeOf < Readonly < LegacyArgsDistributive > > ( ) ;
41
+ const legacyArgsDistributiveB = new Component < LegacyArgsDistributive > (
42
+ { } ,
43
+ { bar : 'hello' , baz : true }
44
+ ) ;
45
+ expectTypeOf ( legacyArgsDistributiveB . args ) . toEqualTypeOf < Readonly < LegacyArgsDistributive > > ( ) ;
46
+
47
+ interface ExtensibleLegacy < T > {
48
+ value : T ;
49
+ extras : boolean ;
50
+ funThings : string [ ] ;
51
+ }
52
+
53
+ class WithExtensibleLegacy < T extends ExtensibleLegacy < unknown > > extends Component < T > { }
54
+ declare const withExtensibleLegacy : WithExtensibleLegacy < ExtensibleLegacy < unknown > > ;
55
+ expectTypeOf ( withExtensibleLegacy . args . value ) . toEqualTypeOf < unknown > ( ) ;
56
+ expectTypeOf ( withExtensibleLegacy . args . extras ) . toEqualTypeOf < boolean > ( ) ;
57
+ expectTypeOf ( withExtensibleLegacy . args . funThings ) . toEqualTypeOf < string [ ] > ( ) ;
58
+
59
+ class WithExtensibleLegacySubclass extends WithExtensibleLegacy < ExtensibleLegacy < string > > { }
60
+ declare const withExtensibleLegacySubclass : WithExtensibleLegacySubclass ;
61
+ expectTypeOf ( withExtensibleLegacySubclass . args . value ) . toEqualTypeOf < string > ( ) ;
28
62
29
63
interface ArgsOnly {
30
- Args : Args ;
64
+ Args : LegacyArgs ;
31
65
}
32
66
33
67
const componentWithArgsOnly = new Component < ArgsOnly > ( { } , { foo : 123 } ) ;
34
- expectTypeOf ( componentWithArgsOnly . args ) . toEqualTypeOf < Readonly < Args > > ( ) ;
68
+ expectTypeOf ( componentWithArgsOnly . args ) . toEqualTypeOf < Readonly < LegacyArgs > > ( ) ;
35
69
36
70
interface ElementOnly {
37
71
Element : HTMLParagraphElement ;
@@ -55,33 +89,33 @@ const componentWithBlockOnly = new Component<BlockOnlySig>({}, {});
55
89
expectTypeOf ( componentWithBlockOnly . args ) . toEqualTypeOf < Readonly < EmptyObject > > ( ) ;
56
90
57
91
interface ArgsAndBlocks {
58
- Args : Args ;
92
+ Args : LegacyArgs ;
59
93
Blocks : Blocks ;
60
94
}
61
95
62
96
const componentwithArgsAndBlocks = new Component < ArgsAndBlocks > ( { } , { foo : 123 } ) ;
63
- expectTypeOf ( componentwithArgsAndBlocks . args ) . toEqualTypeOf < Readonly < Args > > ( ) ;
97
+ expectTypeOf ( componentwithArgsAndBlocks . args ) . toEqualTypeOf < Readonly < LegacyArgs > > ( ) ;
64
98
65
99
interface ArgsAndEl {
66
- Args : Args ;
100
+ Args : LegacyArgs ;
67
101
Element : HTMLParagraphElement ;
68
102
}
69
103
70
104
const componentwithArgsAndEl = new Component < ArgsAndEl > ( { } , { foo : 123 } ) ;
71
- expectTypeOf ( componentwithArgsAndEl . args ) . toEqualTypeOf < Readonly < Args > > ( ) ;
105
+ expectTypeOf ( componentwithArgsAndEl . args ) . toEqualTypeOf < Readonly < LegacyArgs > > ( ) ;
72
106
73
107
interface FullShortSig {
74
- Args : Args ;
108
+ Args : LegacyArgs ;
75
109
Element : HTMLParagraphElement ;
76
110
Blocks : Blocks ;
77
111
}
78
112
79
113
const componentWithFullShortSig = new Component < FullShortSig > ( { } , { foo : 123 } ) ;
80
- expectTypeOf ( componentWithFullShortSig . args ) . toEqualTypeOf < Readonly < Args > > ( ) ;
114
+ expectTypeOf ( componentWithFullShortSig . args ) . toEqualTypeOf < Readonly < LegacyArgs > > ( ) ;
81
115
82
116
interface FullLongSig {
83
117
Args : {
84
- Named : Args ;
118
+ Named : LegacyArgs ;
85
119
Positional : [ ] ;
86
120
} ;
87
121
Element : HTMLParagraphElement ;
@@ -95,4 +129,4 @@ interface FullLongSig {
95
129
}
96
130
97
131
const componentWithFullSig = new Component < FullLongSig > ( { } , { foo : 123 } ) ;
98
- expectTypeOf ( componentWithFullSig . args ) . toEqualTypeOf < Readonly < Args > > ( ) ;
132
+ expectTypeOf ( componentWithFullSig . args ) . toEqualTypeOf < Readonly < LegacyArgs > > ( ) ;
0 commit comments