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

Fix #135 (allow generic type for GrayMatterFile) #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions gray-matter.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type MatterShapeTemplate = Record<string, unknown>

/**
* Takes a string or object with `content` property, extracts
* and parses front-matter from the string, then returns an object
Expand All @@ -15,8 +17,9 @@
*/
declare function matter<
I extends matter.Input,
O extends matter.GrayMatterOption<I, O>
>(input: I | { content: I }, options?: O): matter.GrayMatterFile<I>
O extends matter.GrayMatterOption<I, O>,
MatterShape extends MatterShapeTemplate
>(input: I | { content: I }, options?: O): matter.GrayMatterFile<I, MatterShape>

declare namespace matter {
type Input = string | Buffer
Expand All @@ -36,8 +39,8 @@ declare namespace matter {
language?: string
delimiters?: string | [string, string]
}
interface GrayMatterFile<I extends Input> {
data: { [key: string]: any }
interface GrayMatterFile<I extends Input, MatterShape extends MatterShapeTemplate> {
data: MatterShape
content: string
excerpt?: string
orig: Buffer | I
Expand Down Expand Up @@ -82,10 +85,10 @@ declare namespace matter {
* @param {Object} `options` [Options](#options) to pass to gray-matter.
* @return {Object} Returns [an object](#returned-object) with `data` and `content`
*/
export function read<O extends GrayMatterOption<string, O>>(
export function read<O extends GrayMatterOption<string, O>, MatterShape extends MatterShapeTemplate>(
fp: string,
options?: GrayMatterOption<string, O>
): matter.GrayMatterFile<string>
): matter.GrayMatterFile<string, MatterShape>

/**
* Returns true if the given `string` has front matter.
Expand Down