Skip to content

Commit 33b93a3

Browse files
committed
Fix children types on LayoutFunction
1 parent 2e7e94e commit 33b93a3

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/build-pages/page-data.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function resolveLayout (layoutPath) {
4141
* @param {T} params.vars - All default, global, layout, page, and builder vars shallow merged.
4242
* @param {string[]} [params.scripts] - Array of script URLs to include.
4343
* @param {string[]} [params.styles] - Array of stylesheet URLs to include.
44-
* @param {any} params.children - The children content, either as a string or a render function.
44+
* @param {U} params.children - The children content, either as a string or a render function.
4545
* @param {PageInfo} params.page - Info about the current page
4646
* @param {PageData<T, U, V>[]} params.pages - An array of info about every page
4747
* @param {Object<string, string>} [params.workers] - Map of worker names to their output paths
@@ -249,8 +249,9 @@ export class PageData {
249249
const builder = pageBuilders[pageInfo.type]
250250
const { pageLayout } = await builder({ pageInfo, options: builderOptions })
251251
const renderedPostVars = await this.#renderPostVars({ vars, styles, scripts, pages, page: pageInfo, workers })
252-
// @ts-ignore
253-
return await pageLayout({ vars: renderedPostVars, styles, scripts, pages, page: pageInfo, workers })
252+
// @ts-expect-error - Builder types vary by page type, but the runtime type is correct
253+
const results = await pageLayout({ vars: renderedPostVars, styles, scripts, pages, page: pageInfo, workers })
254+
return results
254255
}
255256

256257
/**
@@ -273,6 +274,7 @@ export class PageData {
273274
scripts,
274275
page: pageInfo,
275276
pages,
277+
// @ts-expect-error - innerPage type varies by page builder but layout handles it
276278
children: innerPage,
277279
workers: this.workers
278280
})

lib/defaults/default.root.layout.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/**
22
* @import { LayoutFunction } from '../build-pages/page-data.js'
3+
* @import { VNode } from 'preact'
34
*/
45
import { html } from 'htm/preact'
56
import { render } from 'preact-render-to-string'
67

78
/**
8-
* @template {Record<string, any>} T
9-
* @typedef {LayoutFunction<T>} LayoutFunction
9+
* @typedef {{
10+
* title: string,
11+
* siteName: string,
12+
* defaultStyle: boolean,
13+
* basePath: string
14+
* }} DefaultRootLayoutVars
1015
*/
1116

1217
/**
1318
* Build all of the bundles using esbuild.
1419
*
15-
* @type {LayoutFunction<{
16-
* title: string,
17-
* siteName: string,
18-
* defaultStyle: boolean,
19-
* basePath: string
20-
* }>}
20+
* @type {LayoutFunction<DefaultRootLayoutVars, string | VNode, string>}
2121
*/
2222
export default function defaultRootLayout ({
2323
vars: {

0 commit comments

Comments
 (0)