Skip to content

Commit a61a0d5

Browse files
committed
Prefer input container in output container type inference
1 parent b9836da commit a61a0d5

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

types/index.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
4646
/**
4747
* Render into a container which is appended to document.body. It should be used with cleanup.
4848
*/
49-
export function render(
50-
ui: React.ReactElement,
51-
options?: Omit<RenderOptions, 'queries'>,
52-
): RenderResult
5349
export function render<
5450
Q extends Queries,
5551
Container extends Element | DocumentFragment = HTMLElement
5652
>(
5753
ui: React.ReactElement,
5854
options: RenderOptions<Q, Container>,
5955
): RenderResult<Q, Container>
56+
export function render(
57+
ui: React.ReactElement,
58+
options?: Omit<RenderOptions, 'queries'>,
59+
): RenderResult
6060

6161
/**
6262
* Unmounts React trees that were mounted with render.

types/test.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ export function testRenderOptions() {
4444
const container = document.createElement('div')
4545
const options = {container}
4646
const {container: returnedContainer} = render(<button />, options)
47-
// Unclear why TypeScript infers `HTMLElement` here when the the input `container` is `HTMLDivElement`.
48-
// It's working for `testSVGRenderOptions`.
49-
// Hopefully this breaks someday and we can switch to
50-
// expectType<HTMLDivElement, typeof returnedContainer>(returnedContainer)
51-
expectType<HTMLElement, typeof returnedContainer>(returnedContainer)
47+
expectType<HTMLDivElement, typeof returnedContainer>(returnedContainer)
5248
}
5349

5450
export function testSVGRenderOptions() {

0 commit comments

Comments
 (0)