Skip to content

Commit

Permalink
Prefer input container in output container type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 1, 2021
1 parent b9836da commit a61a0d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 4 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
/**
* Render into a container which is appended to document.body. It should be used with cleanup.
*/
export function render(
ui: React.ReactElement,
options?: Omit<RenderOptions, 'queries'>,
): RenderResult
export function render<
Q extends Queries,
Container extends Element | DocumentFragment = HTMLElement
>(
ui: React.ReactElement,
options: RenderOptions<Q, Container>,
): RenderResult<Q, Container>
export function render(
ui: React.ReactElement,
options?: Omit<RenderOptions, 'queries'>,
): RenderResult

/**
* Unmounts React trees that were mounted with render.
Expand Down
6 changes: 1 addition & 5 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ export function testRenderOptions() {
const container = document.createElement('div')
const options = {container}
const {container: returnedContainer} = render(<button />, options)
// Unclear why TypeScript infers `HTMLElement` here when the the input `container` is `HTMLDivElement`.
// It's working for `testSVGRenderOptions`.
// Hopefully this breaks someday and we can switch to
// expectType<HTMLDivElement, typeof returnedContainer>(returnedContainer)
expectType<HTMLElement, typeof returnedContainer>(returnedContainer)
expectType<HTMLDivElement, typeof returnedContainer>(returnedContainer)
}

export function testSVGRenderOptions() {
Expand Down

0 comments on commit a61a0d5

Please sign in to comment.