Skip to content

Commit

Permalink
Add type definitions for next/mdx (#36815)
Browse files Browse the repository at this point in the history
Although it’s not intended for use in TypeScript, TypeScript still offers some nice features when it’s used in next.config.js (completion, hovers, `"checkJs": true`).

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
remcohaszing and ijjk authored May 29, 2022
1 parent f7b8131 commit a7eb669
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@babel/core": "7.15.0",
"@babel/eslint-parser": "7.15.0",
"@babel/parser": "7.12.11",
"@babel/generator": "7.15.0",
"@babel/plugin-proposal-object-rest-spread": "7.14.7",
"@babel/preset-flow": "7.14.5",
"@babel/preset-react": "7.14.5",
Expand Down
33 changes: 33 additions & 0 deletions packages/next-mdx/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable */
import { NextConfig } from 'next'
import { CompileOptions } from '@mdx-js/mdx'
import { RuleSetConditionAbsolute } from 'webpack'

type WithMDX = (config: NextConfig) => NextConfig

interface NextMDXOptions {
/**
* A webpack rule test to match files to treat as MDX.
*
* @default /\.mdx$/
* @example
* // Support both .md and .mdx files.
* /\.mdx?$/
*/
extension?: RuleSetConditionAbsolute

/**
* The options to pass to MDX.
*
* @see https://mdxjs.com/packages/mdx/#api
*/
options?: CompileOptions
}

/**
* Use [MDX](https://github.com/mdx-js/mdx) with [Next.js](https://github.com/vercel/next.js)
*/
declare function nextMDX(options?: NextMDXOptions): WithMDX

export = nextMDX
/* eslint=enable */
22 changes: 12 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7eb669

Please sign in to comment.