Skip to content

Commit 167b46b

Browse files
ivoreisyanick
authored andcommitted
build: add generics to allow props, events, slots
1 parent af462d0 commit 167b46b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

types/index.d.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
// Definitions by: Rahim Alwer <https://github.com/mihar-22>
44

55
import {queries, Queries, BoundFunction, EventType} from '@testing-library/dom'
6-
import { SvelteComponent } from 'svelte/types/runtime'
6+
import { SvelteComponentTyped } from 'svelte/types/runtime'
77

88
export * from '@testing-library/dom'
99

10-
type SvelteComponentOptions = any
10+
export interface SvelteComponentOptions<P extends Record<string, any> = any> {
11+
target?: HTMLElement
12+
anchor?: string
13+
props?: P
14+
context?: any
15+
hydrate?: boolean
16+
intro?: boolean
17+
}
1118

1219
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
1320

@@ -16,7 +23,7 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
1623
*/
1724
export type RenderResult<Q extends Queries = typeof queries> = {
1825
container: HTMLElement
19-
component: SvelteComponent
26+
component: SvelteComponentTyped
2027
debug: (el?: HTMLElement | DocumentFragment) => void
2128
rerender: (options: SvelteComponentOptions) => void
2229
unmount: () => void
@@ -28,17 +35,27 @@ export interface RenderOptions<Q extends Queries = typeof queries> {
2835
}
2936

3037
export function render(
31-
component: typeof SvelteComponent,
38+
component: SvelteComponentTyped,
3239
componentOptions?: SvelteComponentOptions,
3340
renderOptions?: Omit<RenderOptions, 'queries'>
3441
): RenderResult
3542

3643
export function render<Q extends Queries>(
37-
component: typeof SvelteComponent,
44+
component: SvelteComponentTyped,
3845
componentOptions?: SvelteComponentOptions,
3946
renderOptions?: RenderOptions<Q>,
4047
): RenderResult<Q>
4148

49+
export function render<
50+
P extends Record<string, any> = any,
51+
E extends Record<string, any> = any,
52+
S extends Record<string, any> = any
53+
>(
54+
component: SvelteComponentTyped<P, E, S>,
55+
componentOptions?: SvelteComponentOptions<P>,
56+
renderOptions?: Omit<RenderOptions, "queries">
57+
): RenderResult;
58+
4259
/**
4360
* Unmounts trees that were mounted with render.
4461
*/

0 commit comments

Comments
 (0)