Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 59338a9

Browse files
committed
Add explicit types tests for ExpandSignature
1 parent a4ebeb1 commit 59338a9

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

test/types/component-test.ts

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Component from '@glimmer/component';
99
// expect to be -- and this keeps us honest about the fact that if we *change*
1010
// this import location, we've broken any existing declarations published using
1111
// the current type signatures.
12-
import { EmptyObject } from '@glimmer/component/addon/-private/component';
12+
import { EmptyObject, ExpandSignature } from '@glimmer/component/addon/-private/component';
1313

1414
declare let basicComponent: Component;
1515
expectTypeOf(basicComponent).toHaveProperty('args');
@@ -30,6 +30,12 @@ type LegacyArgs = {
3030
const componentWithLegacyArgs = new Component<LegacyArgs>({}, { foo: 123 });
3131
expectTypeOf(componentWithLegacyArgs.args).toEqualTypeOf<Readonly<LegacyArgs>>();
3232

33+
expectTypeOf<ExpandSignature<LegacyArgs>>().toEqualTypeOf<{
34+
Args: { Named: LegacyArgs; Positional: [] };
35+
Element: null;
36+
Blocks: EmptyObject;
37+
}>();
38+
3339
// Here, we are testing that the types propertly distribute over union types,
3440
// generics which extend other types, etc.
3541
// Here, we are testing that the types propertly distribute over union types,
@@ -44,6 +50,19 @@ const legacyArgsDistributiveB = new Component<LegacyArgsDistributive>(
4450
);
4551
expectTypeOf(legacyArgsDistributiveB.args).toEqualTypeOf<Readonly<LegacyArgsDistributive>>();
4652

53+
expectTypeOf<ExpandSignature<LegacyArgsDistributive>>().toEqualTypeOf<
54+
| {
55+
Args: { Named: { foo: number }; Positional: [] };
56+
Element: null;
57+
Blocks: EmptyObject;
58+
}
59+
| {
60+
Args: { Named: { bar: string; baz: boolean }; Positional: [] };
61+
Element: null;
62+
Blocks: EmptyObject;
63+
}
64+
>();
65+
4766
interface ExtensibleLegacy<T> {
4867
value: T;
4968
extras: boolean;
@@ -67,6 +86,12 @@ interface ArgsOnly {
6786
const componentWithArgsOnly = new Component<ArgsOnly>({}, { foo: 123 });
6887
expectTypeOf(componentWithArgsOnly.args).toEqualTypeOf<Readonly<LegacyArgs>>();
6988

89+
expectTypeOf<ExpandSignature<ArgsOnly>>().toEqualTypeOf<{
90+
Args: { Named: LegacyArgs; Positional: [] };
91+
Element: null;
92+
Blocks: EmptyObject;
93+
}>();
94+
7095
interface ElementOnly {
7196
Element: HTMLParagraphElement;
7297
}
@@ -75,6 +100,12 @@ const componentWithElOnly = new Component<ElementOnly>({}, {});
75100

76101
expectTypeOf(componentWithElOnly.args).toEqualTypeOf<Readonly<EmptyObject>>();
77102

103+
expectTypeOf<ExpandSignature<ElementOnly>>().toEqualTypeOf<{
104+
Args: { Named: EmptyObject; Positional: [] };
105+
Element: HTMLParagraphElement;
106+
Blocks: EmptyObject;
107+
}>();
108+
78109
interface Blocks {
79110
default: [name: string];
80111
inverse: [];
@@ -88,6 +119,23 @@ const componentWithBlockOnly = new Component<BlockOnlySig>({}, {});
88119

89120
expectTypeOf(componentWithBlockOnly.args).toEqualTypeOf<Readonly<EmptyObject>>();
90121

122+
expectTypeOf<ExpandSignature<BlockOnlySig>>().toEqualTypeOf<{
123+
Args: { Named: EmptyObject; Positional: [] };
124+
Element: null;
125+
Blocks: {
126+
default: {
127+
Params: {
128+
Positional: [name: string];
129+
};
130+
};
131+
inverse: {
132+
Params: {
133+
Positional: [];
134+
};
135+
};
136+
};
137+
}>();
138+
91139
interface ArgsAndBlocks {
92140
Args: LegacyArgs;
93141
Blocks: Blocks;
@@ -96,6 +144,23 @@ interface ArgsAndBlocks {
96144
const componentwithArgsAndBlocks = new Component<ArgsAndBlocks>({}, { foo: 123 });
97145
expectTypeOf(componentwithArgsAndBlocks.args).toEqualTypeOf<Readonly<LegacyArgs>>();
98146

147+
expectTypeOf<ExpandSignature<ArgsAndBlocks>>().toEqualTypeOf<{
148+
Args: { Named: LegacyArgs; Positional: [] };
149+
Element: null;
150+
Blocks: {
151+
default: {
152+
Params: {
153+
Positional: [name: string];
154+
};
155+
};
156+
inverse: {
157+
Params: {
158+
Positional: [];
159+
};
160+
};
161+
};
162+
}>();
163+
99164
interface ArgsAndEl {
100165
Args: LegacyArgs;
101166
Element: HTMLParagraphElement;
@@ -104,6 +169,12 @@ interface ArgsAndEl {
104169
const componentwithArgsAndEl = new Component<ArgsAndEl>({}, { foo: 123 });
105170
expectTypeOf(componentwithArgsAndEl.args).toEqualTypeOf<Readonly<LegacyArgs>>();
106171

172+
expectTypeOf<ExpandSignature<ArgsAndEl>>().toEqualTypeOf<{
173+
Args: { Named: LegacyArgs; Positional: [] };
174+
Element: HTMLParagraphElement;
175+
Blocks: EmptyObject;
176+
}>();
177+
107178
interface FullShortSig {
108179
Args: LegacyArgs;
109180
Element: HTMLParagraphElement;
@@ -113,6 +184,23 @@ interface FullShortSig {
113184
const componentWithFullShortSig = new Component<FullShortSig>({}, { foo: 123 });
114185
expectTypeOf(componentWithFullShortSig.args).toEqualTypeOf<Readonly<LegacyArgs>>();
115186

187+
expectTypeOf<ExpandSignature<FullShortSig>>().toEqualTypeOf<{
188+
Args: { Named: LegacyArgs; Positional: [] };
189+
Element: HTMLParagraphElement;
190+
Blocks: {
191+
default: {
192+
Params: {
193+
Positional: [name: string];
194+
};
195+
};
196+
inverse: {
197+
Params: {
198+
Positional: [];
199+
};
200+
};
201+
};
202+
}>();
203+
116204
interface FullLongSig {
117205
Args: {
118206
Named: LegacyArgs;
@@ -130,3 +218,5 @@ interface FullLongSig {
130218

131219
const componentWithFullSig = new Component<FullLongSig>({}, { foo: 123 });
132220
expectTypeOf(componentWithFullSig.args).toEqualTypeOf<Readonly<LegacyArgs>>();
221+
222+
expectTypeOf<ExpandSignature<FullLongSig>>().toEqualTypeOf<FullLongSig>();

0 commit comments

Comments
 (0)