Skip to content

Commit

Permalink
build: add generics to allow props, events, slots
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoreis authored and yanick committed Apr 7, 2022
1 parent af462d0 commit 167b46b
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
// Definitions by: Rahim Alwer <https://github.com/mihar-22>

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

export * from '@testing-library/dom'

type SvelteComponentOptions = any
export interface SvelteComponentOptions<P extends Record<string, any> = any> {
target?: HTMLElement
anchor?: string
props?: P
context?: any
hydrate?: boolean
intro?: boolean
}

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

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

export function render(
component: typeof SvelteComponent,
component: SvelteComponentTyped,
componentOptions?: SvelteComponentOptions,
renderOptions?: Omit<RenderOptions, 'queries'>
): RenderResult

export function render<Q extends Queries>(
component: typeof SvelteComponent,
component: SvelteComponentTyped,
componentOptions?: SvelteComponentOptions,
renderOptions?: RenderOptions<Q>,
): RenderResult<Q>

export function render<
P extends Record<string, any> = any,
E extends Record<string, any> = any,
S extends Record<string, any> = any
>(
component: SvelteComponentTyped<P, E, S>,
componentOptions?: SvelteComponentOptions<P>,
renderOptions?: Omit<RenderOptions, "queries">
): RenderResult;

/**
* Unmounts trees that were mounted with render.
*/
Expand Down

0 comments on commit 167b46b

Please sign in to comment.