Skip to content

Commit

Permalink
fix(mdx): add additional typings to mdx api (#1211)
Browse files Browse the repository at this point in the history
* feat(mdx): add typings according to the code

* test(mdx): add tests that covers new typings

* Update packages/mdx/types/index.d.ts

* Update packages/mdx/types/index.d.ts

Co-authored-by: John Otander <[email protected]>
  • Loading branch information
lonyele and johno authored Aug 3, 2020
1 parent b8bedc9 commit d76085f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/mdx/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ declare namespace mdx {
*/
footnotes?: boolean

/**
* skip the addition of 'export default' statement when serializing
* to JSX
* @default false
*/
skipExport?: boolean

/**
* wrap 'export default' statement with provided string when serializing
* to JSX
*/
wrapExport?: string

/**
* remark plugins to transform markdown content
*
Expand Down
7 changes: 6 additions & 1 deletion packages/mdx/types/mdx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import * as mdx from '@mdx-js/mdx'
mdx('# title') // $ExpectType Promise<string>
mdx('# title', {}) // $ExpectType Promise<string>
mdx('# title', {footnotes: false}) // $ExpectType Promise<string>
mdx('# title', {skipExport: false}) // $ExpectType Promise<string>
mdx('# title', {wrapExport: 'React.memo'}) // $ExpectType Promise<string>
mdx('# title', {rehypePlugins: [() => () => ({type: 'test'})]}) // $ExpectType Promise<string>
mdx('# title', {remarkPlugins: [() => () => ({type: 'test'})]}) // $ExpectType Promise<string>
mdx('# title', {compilers: []}) // $ExpectType Promise<string>

mdx.sync('# title') // $ExpectType string
mdx.sync('# title', {}) // $ExpectType string
mdx.sync('# title', {footnotes: false}) // $ExpectType string
mdx.sync('# title', {skipExport: false}) // $ExpectType string
mdx.sync('# title', {wrapExport: 'React.memo'}) // $ExpectType string
mdx.sync('# title', {rehypePlugins: [() => () => ({type: 'test'})]}) // $ExpectType string
mdx.sync('# title', {remarkPlugins: [() => () => ({type: 'test'})]}) // $ExpectType string
mdx.sync('# title', {compilers: []}) // $ExpectType string

mdx.createMdxAstCompiler() // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({}) // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({footnotes: false}) // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({skipExport: false}) // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({wrapExport: 'React.memo'}) // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({rehypePlugins: [() => () => ({type: 'test'})]}) // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({remarkPlugins: [() => () => ({type: 'test'})]}) // $ExpectType Processor<Settings>
mdx.createMdxAstCompiler({compilers: []}) // $ExpectType Processor<Settings>

0 comments on commit d76085f

Please sign in to comment.