|
4 | 4 | ComponentSignatureBlocks, |
5 | 5 | ComponentSignatureElement, |
6 | 6 | } from '../-private/signature'; |
| 7 | +import { ComponentLike } from '../'; |
7 | 8 |
|
8 | 9 | type LegacyArgs = { |
9 | 10 | foo: number; |
@@ -153,3 +154,56 @@ interface FullLongSig { |
153 | 154 | expectTypeOf<ComponentSignatureArgs<FullLongSig>>().toEqualTypeOf<FullLongSig['Args']>(); |
154 | 155 | expectTypeOf<ComponentSignatureBlocks<FullLongSig>>().toEqualTypeOf<FullLongSig['Blocks']>(); |
155 | 156 | expectTypeOf<ComponentSignatureElement<FullLongSig>>().toEqualTypeOf<FullLongSig['Element']>(); |
| 157 | + |
| 158 | +// types to simulate the `(element)` helper |
| 159 | +// Issue: https://github.com/typed-ember/glint/issues/610 |
| 160 | +type ElementFromTagName<T extends string> = T extends keyof HTMLElementTagNameMap |
| 161 | + ? HTMLElementTagNameMap[T] |
| 162 | + : Element; |
| 163 | +type ElementHelperPositional<T extends string> = [name: T]; |
| 164 | +type ElementHelperReturn<T extends string> = ComponentLike<{ |
| 165 | + Element: ElementFromTagName<T>; |
| 166 | + Blocks: { default: [] }; |
| 167 | +}>; |
| 168 | + |
| 169 | +interface ElementSignature<T extends string> { |
| 170 | + Args: { |
| 171 | + Positional: ElementHelperPositional<T>; |
| 172 | + }; |
| 173 | + Return: ElementHelperReturn<T> | undefined; |
| 174 | +} |
| 175 | + |
| 176 | +// signature for a component receiving an `(element)` |
| 177 | +interface ElementReceiverSignature<T extends string> { |
| 178 | + Element: ElementFromTagName<T>; |
| 179 | + Args: { |
| 180 | + element: ElementSignature<T>['Return']; |
| 181 | + }; |
| 182 | + Blocks: { |
| 183 | + default: []; |
| 184 | + }; |
| 185 | +} |
| 186 | + |
| 187 | +expectTypeOf<ComponentSignatureArgs<ElementReceiverSignature<'div'>>>().toEqualTypeOf<{ |
| 188 | + Named: { |
| 189 | + element: ElementSignature<'div'>['Return']; |
| 190 | + }; |
| 191 | + Positional: [] |
| 192 | +}>(); |
| 193 | + |
| 194 | +expectTypeOf<ComponentSignatureArgs<ElementReceiverSignature<null>>>().toEqualTypeOf<{ |
| 195 | + Named: { |
| 196 | + element: { |
| 197 | + Args: { |
| 198 | + Positional: ElementHelperPositional<never>; |
| 199 | + }; |
| 200 | + Return: ComponentLike<{ |
| 201 | + Element: Element; |
| 202 | + Blocks: { default: [] }; |
| 203 | + }> | undefined; |
| 204 | + } | undefined; |
| 205 | + }; |
| 206 | + Positional: [] |
| 207 | +}>(); |
| 208 | +expectTypeOf<ComponentSignatureElement<ElementReceiverSignature<'div'>>>().toEqualTypeOf<HTMLDivElement>(); |
| 209 | + |
0 commit comments