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
Remove Directive type from createInfiniteScroll #619
base: main
Are you sure you want to change the base?
Conversation
|
Don’t use Ref, but a maybe a better type could be inlined there instead. |
// How `Directive` type is created in the signal, meets constraints of `Ref` below
let add: (el: Element) => void = noop;
/**
* Type of `props.ref`, for use in `Component` or `props` typing.
*
* @example Component<{ref: Ref<Element>}>
*/
export type Ref<T> = T | ((val: T) => void);
`` |
forgot solid now exports |
Update: I had a ts-ignore in one place so I was mislead. The error still persists and I think is because For reference this is what I'm doing now with the updated type def you suggested: Component /**
* Using these extra types allows the generic type passed into `Ref` to be narrowed
* based on the variant that the consumer passes in.
*/
type HeadingVariantProps = {
variant: "heading" | "subheading" | "title" | "subtitle";
ref?: HTMLHeadingElement | ((el: HTMLHeadingElement) => void);
};
type BodyVariantProps = {
variant: "body";
ref?: HTMLParagraphElement | ((el: HTMLParagraphElement) => void);
};
type DefaultVariantProps = {
variant?: undefined;
ref?: HTMLSpanElement | ((el: HTMLSpanElement) => void);
};
export type TypographyProps = ParentProps & {
color?: keyof Theme["colors"];
spacing?: Theme["spacing"];
wrap?: boolean;
} & (HeadingVariantProps | BodyVariantProps | DefaultVariantProps); Consumer with loader <Typography ref={loaderRef}>Loading...</Typography> TS Error
|
I meant that |
Understood 👍🏼 I can update this PR to make that change. Thank you for talking through this with me. @thetarnav updated! |
@thetarnav Does this look okay now to merge? |
I'm getting an error in a project of mine which has a custom component. This component accepts a
ref
essentially asref?: Ref<HTMLSpanElement>
(other details omitted for brevity).When consuming the component and passing in the loadingRef from this primitive I get this error
If I'm understanding the intent of the
Directive
return type here, it really is just a ref - this is correct? If this approach isn't preferred, does anyone have a suggestion on how I can accommodate forDirective
andRef
?