Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve frontmatter types, pass generic TFrontmatter type through #342

Merged
merged 5 commits into from
Feb 28, 2023

Conversation

BRKalow
Copy link
Contributor

@BRKalow BRKalow commented Feb 13, 2023

Update serialize() and compileMDX() to accept generics for scope and frontmatter. Pass through the generic to ensure that the return types reflect the provided frontmatter types.

serialize:

import { serialize } from 'next-mdx-remote/serialize'

interface Frontmatter {
  title: string
  published: string
  description?: string
}

//     👇 should have type Frontmatter
const { frontmatter } = serialize<Record<string, unknown>, Frontmatter>(source)

compileMDX:

import { compileMDX } from 'next-mdx-remote/rsc'

interface Frontmatter {
  title: string
  published: string
  description?: string
}

export default async function Page({ source }) {
	//              👇 should have type Frontmatter
	const { content, frontmatter } = await compileMDX<Frontmatter>(source)

	return (
		<>
			<h1>{frontmatter.title}</h1>
			{content}
		</>
	)
}

@BRKalow BRKalow marked this pull request as ready for review February 27, 2023 23:31
@BRKalow BRKalow requested a review from a team February 27, 2023 23:56
Copy link
Contributor

@thiskevinwang thiskevinwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New typings look good to me! (via VSCode TS compiler)

@BRKalow BRKalow merged commit 2b35582 into main Feb 28, 2023
@BRKalow BRKalow deleted the brk.feat/improve-frontmatter-types branch February 28, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants