-
Notifications
You must be signed in to change notification settings - Fork 58
Fix problem with transitive generics in Signatures #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
ComponentSignatureBlocks, | ||
ComponentSignatureElement, | ||
} from '../-private/signature'; | ||
import { ComponentLike } from '../'; | ||
|
||
type LegacyArgs = { | ||
foo: number; | ||
|
@@ -153,3 +154,56 @@ interface FullLongSig { | |
expectTypeOf<ComponentSignatureArgs<FullLongSig>>().toEqualTypeOf<FullLongSig['Args']>(); | ||
expectTypeOf<ComponentSignatureBlocks<FullLongSig>>().toEqualTypeOf<FullLongSig['Blocks']>(); | ||
expectTypeOf<ComponentSignatureElement<FullLongSig>>().toEqualTypeOf<FullLongSig['Element']>(); | ||
|
||
// types to simulate the `(element)` helper | ||
// Issue: https://github.com/typed-ember/glint/issues/610 | ||
type ElementFromTagName<T extends string> = T extends keyof HTMLElementTagNameMap | ||
? HTMLElementTagNameMap[T] | ||
: Element; | ||
type ElementHelperPositional<T extends string> = [name: T]; | ||
type ElementHelperReturn<T extends string> = ComponentLike<{ | ||
Element: ElementFromTagName<T>; | ||
Blocks: { default: [] }; | ||
}>; | ||
|
||
interface ElementSignature<T extends string> { | ||
Args: { | ||
Positional: ElementHelperPositional<T>; | ||
}; | ||
Return: ElementHelperReturn<T> | undefined; | ||
} | ||
|
||
// signature for a component receiving an `(element)` | ||
interface ElementReceiverSignature<T extends string> { | ||
Element: ElementFromTagName<T>; | ||
Args: { | ||
element: ElementSignature<T>['Return']; | ||
}; | ||
Blocks: { | ||
default: []; | ||
}; | ||
} | ||
|
||
expectTypeOf<ComponentSignatureArgs<ElementReceiverSignature<'div'>>>().toEqualTypeOf<{ | ||
Named: { | ||
element: ElementSignature<'div'>['Return']; | ||
}; | ||
Positional: [] | ||
}>(); | ||
|
||
expectTypeOf<ComponentSignatureArgs<ElementReceiverSignature<null>>>().toEqualTypeOf<{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this line is the problematic part here, I'd say. For what I think needs to be tested, is how the components are invoked, rather than the static definition? That is, in invocation, this should be
To my knowledge, to properly test this, is to provide broken types. How to do that? |
||
Named: { | ||
element: { | ||
Args: { | ||
Positional: ElementHelperPositional<never>; | ||
}; | ||
Return: ComponentLike<{ | ||
Element: Element; | ||
Blocks: { default: [] }; | ||
}> | undefined; | ||
} | undefined; | ||
}; | ||
Positional: [] | ||
}>(); | ||
expectTypeOf<ComponentSignatureElement<ElementReceiverSignature<'div'>>>().toEqualTypeOf<HTMLDivElement>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a temporary revert. That is to write failing tests, which when switching back to the fix should be resolved.