diff --git a/packages/template/-private/signature.d.ts b/packages/template/-private/signature.d.ts index 7d525fe24..00baf4481 100644 --- a/packages/template/-private/signature.d.ts +++ b/packages/template/-private/signature.d.ts @@ -45,7 +45,8 @@ export type ComponentSignatureBlocks = S extends { Blocks: infer Blocks } /** Given a component signature `S`, get back the `Element` type. */ export type ComponentSignatureElement = S extends { Element: infer Element } - ? NonNullable extends never + ? NonNullable extends never +// ? Element extends null ? unknown : Element : unknown; diff --git a/packages/template/__tests__/signature.test.ts b/packages/template/__tests__/signature.test.ts index fa59161d1..d696a3f44 100644 --- a/packages/template/__tests__/signature.test.ts +++ b/packages/template/__tests__/signature.test.ts @@ -4,6 +4,7 @@ import { ComponentSignatureBlocks, ComponentSignatureElement, } from '../-private/signature'; +import { ComponentLike } from '../'; type LegacyArgs = { foo: number; @@ -153,3 +154,56 @@ interface FullLongSig { expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); + +// types to simulate the `(element)` helper +// Issue: https://github.com/typed-ember/glint/issues/610 +type ElementFromTagName = T extends keyof HTMLElementTagNameMap + ? HTMLElementTagNameMap[T] + : Element; +type ElementHelperPositional = [name: T]; +type ElementHelperReturn = ComponentLike<{ + Element: ElementFromTagName; + Blocks: { default: [] }; +}>; + +interface ElementSignature { + Args: { + Positional: ElementHelperPositional; + }; + Return: ElementHelperReturn | undefined; +} + +// signature for a component receiving an `(element)` +interface ElementReceiverSignature { + Element: ElementFromTagName; + Args: { + element: ElementSignature['Return']; + }; + Blocks: { + default: []; + }; +} + +expectTypeOf>>().toEqualTypeOf<{ + Named: { + element: ElementSignature<'div'>['Return']; + }; + Positional: [] +}>(); + +expectTypeOf>>().toEqualTypeOf<{ + Named: { + element: { + Args: { + Positional: ElementHelperPositional; + }; + Return: ComponentLike<{ + Element: Element; + Blocks: { default: [] }; + }> | undefined; + } | undefined; + }; + Positional: [] +}>(); +expectTypeOf>>().toEqualTypeOf(); +