Skip to content

Commit 08ca639

Browse files
feat: add typings for @mdx-js/runtime
1 parent d7ea02f commit 08ca639

File tree

8 files changed

+91
-10
lines changed

8 files changed

+91
-10
lines changed

packages/mdx/types/index.d.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ declare namespace mdx {
99
*
1010
* @default true
1111
*/
12-
footnotes?: boolean
12+
footnotes: boolean
1313

1414
/**
1515
* remark plugins to transform markdown content
1616
*
1717
* @default []
1818
*/
19-
remarkPlugins?: Plugin[]
19+
remarkPlugins: Plugin[]
2020

2121
/**
2222
* rehype plugins html content
2323
*
2424
* @default []
2525
*/
26-
rehypePlugins?: Plugin[]
26+
rehypePlugins: Plugin[]
2727

2828
/**
2929
* compilers to customize output
3030
*
3131
* @default []
3232
*/
33-
compilers?: Compiler[]
33+
compilers: Compiler[]
3434
}
3535

3636
/**
@@ -40,15 +40,15 @@ declare namespace mdx {
4040
* @param options transform and compiler options
4141
* @returns jsx text
4242
*/
43-
function sync(mdx: string, options?: Options): string
43+
function sync(mdx: string, options?: Partial<Options>): string
4444

4545
/**
4646
* Generated an MDX compiler
4747
*
4848
* @param options transform and compiler options
4949
* @returns Unified Processor for MDX
5050
*/
51-
function createMdxAstCompiler(options?: Options): Processor
51+
function createMdxAstCompiler(options?: Partial<Options>): Processor
5252
}
5353

5454
/**
@@ -58,6 +58,6 @@ declare namespace mdx {
5858
* @param options transform and compiler options
5959
* @returns jsx text
6060
*/
61-
declare function mdx(mdx: string, options?: mdx.Options): Promise<string>
61+
declare function mdx(mdx: string, options?: Partial<mdx.Options>): Promise<string>
6262

6363
export = mdx

packages/react/types/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ interface ComponentDictionary {
2020
* Prop type that includes a component dictionary
2121
*/
2222
interface ComponentsProp {
23+
/**
24+
* Mapping of names for JSX components to React components
25+
*/
2326
components: ComponentDictionary
2427
}
2528

packages/runtime/package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@
1919
"John Otander <[email protected]> (http://johnotander.com)",
2020
"Tim Neutkens <[email protected]>",
2121
"Matija Marohnić <[email protected]>",
22-
"Titus Wormer <[email protected]> (https://wooorm.com)"
22+
"Titus Wormer <[email protected]> (https://wooorm.com)",
23+
"Christian Murphy <[email protected]>"
2324
],
2425
"main": "dist/index.js",
2526
"module": "dist/index.es.js",
2627
"scripts": {
2728
"build": "microbundle --format es,cjs --external react,buble,@mdx-js/mdx,@mdx-js/react --jsx React.createElement --no-sourcemap",
2829
"clean": "rimraf dist",
2930
"prepublish": "yarn clean && yarn build",
30-
"test": "jest"
31+
"test": "jest && dtslint types"
3132
},
3233
"files": [
33-
"dist"
34+
"dist",
35+
"types/index.d.ts"
3436
],
37+
"types": "types/index.d.ts",
3538
"dependencies": {
3639
"@mdx-js/mdx": "^1.4.5",
3740
"@mdx-js/react": "^1.4.5",
@@ -41,6 +44,7 @@
4144
"@babel/core": "7.6.0",
4245
"@babel/preset-env": "7.6.0",
4346
"@babel/preset-react": "7.0.0",
47+
"dtslint": "^0.9.8",
4448
"jest": "24.9.0",
4549
"microbundle": "0.11.0",
4650
"react": "16.9.0",

packages/runtime/types/index.d.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// TypeScript Version: 3.5
2+
3+
import { FunctionComponent } from 'react'
4+
import { Options } from '@mdx-js/mdx'
5+
import { ComponentsProp } from '@mdx-js/react'
6+
7+
/**
8+
* Properties for the MDX Runtime component
9+
*/
10+
export interface MDXRuntimeProps extends Omit<Options, 'footnotes' | 'compilers'>, ComponentsProp {
11+
/**
12+
* MDX text
13+
*/
14+
children: string
15+
16+
/**
17+
* Values in usable in MDX scope
18+
*/
19+
scope: {
20+
[variableName: string]: unknown
21+
}
22+
}
23+
24+
/**
25+
* Renders child MDX text as a React component
26+
*/
27+
declare const mdxRuntime: FunctionComponent<Partial<MDXRuntimeProps>>
28+
29+
export default mdxRuntime
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from 'react'
2+
import MDX from '@mdx-js/runtime'
3+
4+
const exampleNoProps = () => <MDX># header</MDX>
5+
6+
// $ExpectError
7+
const exampleInvalidContent = () => <MDX children={<div />}></MDX>
8+
9+
const exampleScopeAndComponents = (mdx: string) => (
10+
<MDX components={{h1: () => <h1 />}} scope={{value: 'example'}}>
11+
{mdx}
12+
</MDX>
13+
)
14+
15+
const exampleFullConfig = (mdx: string) => (
16+
<MDX
17+
components={{h1: () => <h1 />}}
18+
scope={{value: 'example', number: 1}}
19+
rehypePlugins={[() => () => ({type: 'test'})]}
20+
remarkPlugins={[() => () => ({type: 'test'})]}
21+
>
22+
{mdx}
23+
</MDX>
24+
)

packages/runtime/types/tsconfig.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["dom", "es6"],
5+
"strict": true,
6+
"noEmit": true,
7+
"baseUrl": ".",
8+
"jsx": "react",
9+
"paths": {
10+
"@mdx-js/runtime": ["index.d.ts"]
11+
}
12+
}
13+
}

packages/runtime/types/tslint.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"whitespace": false,
5+
"semicolon": false,
6+
"no-redundant-jsdoc": false
7+
}
8+
}
File renamed without changes.

0 commit comments

Comments
 (0)