Skip to content
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

bug: must use the class type not the instance type #195

Closed
wants to merge 2 commits into from

Conversation

yanick
Copy link
Collaborator

@yanick yanick commented Jun 2, 2022

Potential solution for #194

Basically, what render gets is the class, not instances of that class.

Also, for the options, we were not dealing well with the shortcut of passing the props directly.

@@ -7,14 +7,16 @@ import { SvelteComponentTyped } from 'svelte/types/runtime'

export * from '@testing-library/dom'

export interface SvelteComponentOptions<P extends Record<string, any> = any> {
type SvelteComponentTypedClass<P,E,S> = typeof SvelteComponentTyped<P,E,S>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so for some reason, typeof doesn't really play nicely when it comes to generics. I'm not sure if TypeScript gives an escape hatch for that. But what's currently here may not work.

Copy link

@molily molily Jun 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for me either, TS cannot parse this. If I understand correctly, the class definition should be something like

type SvelteComponentTypedClass<P, E, S> = new (options: SvelteComponentOptions<P>) => SvelteComponentTyped<P, E, S>;

See also svelte2tsx:
https://github.com/sveltejs/language-tools/blob/1415196df7118f4361385a6450ff2756bca3ff00/packages/svelte2tsx/svelte-shims.d.ts#L56-L76

(If I use this type definition I still get clashes with the svelte2tsx's generated component type definition, since it's target: Element | ShadowRoot from svelte2tsx and target?: HTMLElement in types/index.d.ts.)

@mcous
Copy link
Collaborator

mcous commented Jan 29, 2024

@yanick since this PR was written, SvelteComponentTyped has been deprecated by Svelte. It looks like maybe some other things have changed, too.

I think the current typings that use ComponentConstructorOptions to accept constructor that returns a SvelteComponent instance are acceptable. This PR can probably be closed

@yanick
Copy link
Collaborator Author

yanick commented Jan 29, 2024

Agreed!

@yanick yanick closed this Jan 29, 2024
@mcous mcous deleted the typescript-type branch June 2, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants