Skip to content

Commit 2c5e5c1

Browse files
committed
feat(client): make usePageFrontmatter generic
1 parent 8a7025f commit 2c5e5c1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/@vuepress/client/src/injections/pageFrontmatter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import type { ComputedRef, InjectionKey } from 'vue'
33
import type { PageData, PageFrontmatter } from '@vuepress/shared'
44

55
export type { PageFrontmatter }
6-
export type PageFrontmatterRef = ComputedRef<PageFrontmatter>
6+
export type PageFrontmatterRef<
7+
T extends Record<any, any> = Record<string, unknown>
8+
> = ComputedRef<PageFrontmatter<T>>
79

810
export const pageFrontmatterSymbol: InjectionKey<PageFrontmatterRef> = Symbol(
911
__DEV__ ? 'pageFrontmatter' : ''
1012
)
1113

12-
export const usePageFrontmatter = (): PageFrontmatterRef => {
14+
export const usePageFrontmatter = <
15+
T extends Record<any, any> = Record<string, unknown>
16+
>(): PageFrontmatterRef<T> => {
1317
const pageFrontmatter = inject(pageFrontmatterSymbol)
1418
if (!pageFrontmatter) {
1519
throw new Error('usePageFrontmatter() is called without provider.')
1620
}
17-
return pageFrontmatter
21+
return pageFrontmatter as PageFrontmatterRef<T>
1822
}
1923

2024
export const resolvePageFrontmatter = (pageData: PageData): PageFrontmatter =>

0 commit comments

Comments
 (0)