Skip to content

Commit

Permalink
[v3] add a generic for themeConfig to improve type inference (#3140)
Browse files Browse the repository at this point in the history
  • Loading branch information
87xie authored Aug 24, 2024
1 parent 6945f38 commit 7bb18e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/poor-rings-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nextra-theme-blog': patch
'nextra-theme-docs': patch
'nextra': patch
---

Add a generic for `themeConfig` in `NextraThemeLayoutProps` to improve type inference.
4 changes: 2 additions & 2 deletions packages/nextra-theme-blog/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { components, HeadingContext } from './mdx-theme'
import Meta from './meta'
import Nav from './nav'
import { PostsLayout } from './posts-layout'
import type { BlogFrontMatter } from './types'
import type { BlogFrontMatter, NextraBlogTheme } from './types'
import { isValidDate } from './utils/date'

const layoutSet = new Set(['post', 'page', 'posts', 'tag'])
Expand All @@ -18,7 +18,7 @@ export default function NextraLayout({
children,
pageOpts,
themeConfig
}: NextraThemeLayoutProps<BlogFrontMatter>) {
}: NextraThemeLayoutProps<BlogFrontMatter, NextraBlogTheme>) {
const config = { ...DEFAULT_THEME, ...themeConfig }

const ref = useRef<HTMLHeadingElement>(null)
Expand Down
9 changes: 6 additions & 3 deletions packages/nextra/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ export type Nextra = (

export type ThemeConfig = any | null

export type NextraThemeLayoutProps<F = FrontMatter> = {
pageOpts: PageOpts<F>
export type NextraThemeLayoutProps<
TFrontMatter = FrontMatter,
TThemeConfig = ThemeConfig
> = {
pageOpts: PageOpts<TFrontMatter>
pageProps: any
themeConfig: ThemeConfig
themeConfig: TThemeConfig
children: ReactNode
}

Expand Down

0 comments on commit 7bb18e3

Please sign in to comment.