Skip to content

Commit e27b8c5

Browse files
fix: better render type (#11997)
Closes #11996 --------- Co-authored-by: Simon Holthausen <[email protected]>
1 parent 7272b65 commit e27b8c5

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

.changeset/funny-cooks-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: better `render` type

packages/svelte/src/internal/server/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ export function element(payload, tag, attributes_fn, children_fn) {
9393
export let on_destroy = [];
9494

9595
/**
96-
* @param {typeof import('svelte').SvelteComponent} component
97-
* @param {{ props: Record<string, any>; context?: Map<any, any> }} options
96+
* Only available on the server and when compiling with the `server` option.
97+
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
98+
* @template {Record<string, any>} Props
99+
* @param {import('svelte').Component<Props> | import('svelte').ComponentType<import('svelte').SvelteComponent<Props>>} component
100+
* @param {{ props: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }} options
98101
* @returns {import('#server').RenderOutput}
99102
*/
100103
export function render(component, options) {

packages/svelte/tests/types/component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
hydrate,
99
type Component
1010
} from 'svelte';
11+
import { render } from 'svelte/server';
1112

1213
SvelteComponent.element === HTMLElement;
1314

@@ -148,6 +149,14 @@ hydrate(NewComponent, {
148149
recover: false
149150
});
150151

152+
render(NewComponent, {
153+
props: {
154+
prop: 'foo',
155+
// @ts-expect-error
156+
x: ''
157+
}
158+
});
159+
151160
// --------------------------------------------------------------------------- interop
152161

153162
const AsLegacyComponent = asClassComponent(newComponent);
@@ -256,3 +265,12 @@ hydrate(functionComponent, {
256265
binding: true
257266
}
258267
});
268+
269+
render(functionComponent, {
270+
props: {
271+
binding: true,
272+
readonly: 'foo',
273+
// @ts-expect-error
274+
x: ''
275+
}
276+
});

packages/svelte/types/index.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,9 +2108,13 @@ declare module 'svelte/reactivity' {
21082108
}
21092109

21102110
declare module 'svelte/server' {
2111-
export function render(component: typeof import('svelte').SvelteComponent, options: {
2112-
props: Record<string, any>;
2113-
context?: Map<any, any>;
2111+
/**
2112+
* Only available on the server and when compiling with the `server` option.
2113+
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
2114+
* */
2115+
export function render<Props extends Record<string, any>>(component: import("svelte").Component<Props, any, string> | import("svelte").ComponentType<import("svelte").SvelteComponent<Props, any, any>>, options: {
2116+
props: Omit<Props, "$$slots" | "$$events">;
2117+
context?: Map<any, any> | undefined;
21142118
}): RenderOutput;
21152119
interface RenderOutput {
21162120
/** HTML that goes into the `<head>` */

0 commit comments

Comments
 (0)