-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add Generic Data Typing for matter Frontmatter Parsing #168
Comments
I should mention that I'm doing a type casting using type Content = GrayMatterFile<string> & {
data: { title: string, description: string }
}
const content = parsedContent as Content |
I would enjoy a similar feature. As is, I'm just assigning a new object from my file parsing function using just the fields I expect, and returning that, but being able to specify the type on the return from |
Actually, it looks like this issue has been brought up before, and has been open for a long time with no feedback from the library author. Kind of disappointing. |
I am trying to find where but someone posted this code snippet and its made my life easier
|
The
matter
function currently returns aGrayMatterFile<string>
, which loses type information about the expecteddata
shape.It would be better to allow passing a generic type parameter for the
data
property, like this:This way consumer code could get type safety when accessing the metadata.
For example in my case I'm parsing MDX files that expect title and description in the frontmatter. With generic data types I could get code completion and validation for those fields.
Potentially the GrayMatterFile type could be updated to add a second generic parameter:
Please let me know your idea, and even let me know if I can do this in the current version of the lovely
gray-matter
.The text was updated successfully, but these errors were encountered: