-
Notifications
You must be signed in to change notification settings - Fork 140
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 TypeScript definition file #75
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Type definitions for next-mdx-remote | ||
// Project: https://github.com/hashicorp/next-mdx-remote | ||
// Definitions by: Steven Schmatz <https://github.com/stevenschmatz> | ||
|
||
declare module 'next-mdx-remote/render-to-string' { | ||
import * as React from 'react'; | ||
|
||
/** | ||
* Runs the MDX renderer on the MDX string provided with the components and data provided. | ||
*/ | ||
export default function renderToString( | ||
/** Raw MDX contents as a string. */ | ||
source: string, | ||
/** Optional parameters, such as components, plugins, and data. */ | ||
params?: { | ||
/** | ||
* A object mapping names to React components. | ||
* The key used will be the name accessible to MDX. | ||
* | ||
* For example: `{ ComponentName: Component }` will be accessible in the MDX as `<ComponentName/>`. | ||
*/ | ||
components?: { | ||
[componentName: string]: React.FunctionComponent | React.Component; | ||
}; | ||
/** | ||
* An arbitrary object of data which will be supplied to the MDX. | ||
* | ||
* For example, in cases where you want to provide template variables to the MDX, like `my name is {name}`, | ||
* you could provide scope as `{ name: "Some name" }`. | ||
*/ | ||
scope?: object; | ||
/** | ||
* These options are passed to the MDX compiler. | ||
* See [the MDX docs.](https://github.com/mdx-js/mdx/blob/master/packages/mdx/index.js). | ||
*/ | ||
mdxOptions?: { | ||
remarkPlugins?: any[]; | ||
rehypePlugins?: any[]; | ||
hastPlugins?: any[]; | ||
compilers?: any[]; | ||
filepath?: string; | ||
}; | ||
} | ||
): Promise<{ | ||
compiledSource: string; | ||
renderedOutput: string; | ||
scope?: Record<string, unknown>; | ||
}>; | ||
} | ||
|
||
declare module 'next-mdx-remote/hydrate' { | ||
import * as React from 'react'; | ||
|
||
/** | ||
* Consumes the output of `renderToString` as well as the same components argument as `renderToString`. | ||
* Its result can be rendered directly into your component. | ||
* | ||
* This function is intended to run on the **client-side**. | ||
* It will initially render static content, and hydrate it when the browser isn't busy with higher priority tasks. | ||
* | ||
* For more information and examples, consult [the documentation](https://github.com/hashicorp/next-mdx-remote#apis). | ||
*/ | ||
export default function hydrate( | ||
/** Rendered MDX output. The direct output of `renderToString`. */ | ||
source: { | ||
compiledSource: string; | ||
renderedOutput: string; | ||
scope?: Record<string, unknown>; | ||
}, | ||
/** | ||
* A map of names to React components. | ||
* The key used will be the name accessible to MDX. | ||
* | ||
* For example: `{ ComponentName: Component }` will be accessible in the MDX as `<ComponentName/>`. | ||
*/ | ||
params?: { | ||
[componentName: string]: React.FunctionComponent | React.Component; | ||
} | ||
): React.ReactNode; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was working on type definitions, I also found that I needed to specify this type in this way instead of just
React.Element
, but was confused about why. Do you have any further insight on this one?