Skip to content

Commit 9c53c68

Browse files
committed
Add manual types to index.d.ts
1 parent 1a79d23 commit 9c53c68

File tree

6 files changed

+101
-83
lines changed

6 files changed

+101
-83
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
coverage/
22
node_modules/
3-
index.d.ts
4-
test.d.ts
3+
*.d.ts
54
*.log
65
.DS_Store
76
yarn.lock
7+
!/complex-types.d.ts
8+
!/index.d.ts

index.d.ts

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import type {
2+
Node as MdastNode,
3+
Parent as MdastParent,
4+
Literal as MdastLiteral,
5+
BlockContent,
6+
PhrasingContent
7+
} from 'mdast'
8+
import type {Program} from 'estree-jsx'
9+
10+
// Expose JavaScript API.
11+
export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js'
12+
13+
// Expose options.
14+
export type {ToMarkdownOptions} from './lib/index.js'
15+
16+
// Expose node types.
17+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
18+
export interface MdxJsxAttributeValueExpression extends MdastLiteral {
19+
type: 'mdxJsxAttributeValueExpression'
20+
data?: {estree?: Program} & MdastLiteral['data']
21+
}
22+
23+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
24+
export interface MdxJsxExpressionAttribute extends MdastLiteral {
25+
type: 'mdxJsxExpressionAttribute'
26+
data?: {estree?: Program} & MdastLiteral['data']
27+
}
28+
29+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
30+
export interface MdxJsxAttribute extends MdastNode {
31+
type: 'mdxJsxAttribute'
32+
name: string
33+
value?: MdxJsxAttributeValueExpression | string | null | undefined
34+
}
35+
36+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
37+
interface MdxJsxElementFields {
38+
name: string | null
39+
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
40+
}
41+
42+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
43+
export interface MdxJsxFlowElement extends MdxJsxElementFields, MdastParent {
44+
type: 'mdxJsxFlowElement'
45+
children: BlockContent[]
46+
}
47+
48+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
49+
export interface MdxJsxTextElement extends MdxJsxElementFields, MdastParent {
50+
type: 'mdxJsxTextElement'
51+
children: PhrasingContent[]
52+
}
53+
54+
// Add nodes to mdast content.
55+
declare module 'mdast' {
56+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
57+
interface StaticPhrasingContentMap {
58+
mdxJsxTextElement: MdxJsxTextElement
59+
}
60+
61+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
62+
interface BlockContentMap {
63+
mdxJsxFlowElement: MdxJsxFlowElement
64+
}
65+
}
66+
67+
// Add nodes to hast content.
68+
declare module 'hast' {
69+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
70+
interface RootContentMap {
71+
mdxJsxTextElement: MdxJsxTextElement
72+
mdxJsxFlowElement: MdxJsxFlowElement
73+
}
74+
75+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
76+
interface ElementContentMap {
77+
mdxJsxTextElement: MdxJsxTextElement
78+
mdxJsxFlowElement: MdxJsxFlowElement
79+
}
80+
}

index.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
/**
2-
* @typedef {import('./lib/index.js').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
3-
* @typedef {import('./lib/index.js').MdxJsxAttribute} MdxJsxAttribute
4-
* @typedef {import('./lib/index.js').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute
5-
* @typedef {import('./lib/index.js').MdxJsxFlowElement} MdxJsxFlowElement
6-
* @typedef {import('./lib/index.js').MdxJsxTextElement} MdxJsxTextElement
7-
* @typedef {import('./lib/index.js').ToMarkdownOptions} ToMarkdownOptions
8-
*/
9-
1+
// Note: types exposed from `index.d.ts`.
102
export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js'

lib/complex-types.d.ts

+11-66
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,11 @@
1-
import type {Node} from 'unist'
2-
import type {Parent, Literal, BlockContent, PhrasingContent} from 'mdast'
3-
import type {Program} from 'estree-jsx'
4-
5-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
6-
export interface MdxJsxAttributeValueExpression extends Literal {
7-
type: 'mdxJsxAttributeValueExpression'
8-
data?: {estree?: Program} & Literal['data']
9-
}
10-
11-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
12-
export interface MdxJsxAttribute extends Node {
13-
type: 'mdxJsxAttribute'
14-
name: string
15-
value?: MdxJsxAttributeValueExpression | string | null
16-
}
17-
18-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
19-
export interface MdxJsxExpressionAttribute extends Literal {
20-
type: 'mdxJsxExpressionAttribute'
21-
data?: {estree?: Program} & Literal['data']
22-
}
23-
24-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
25-
interface MdxJsxElementFields {
26-
name: string | null
27-
attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>
28-
}
29-
30-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
31-
export interface MdxJsxFlowElement extends MdxJsxElementFields, Parent {
32-
type: 'mdxJsxFlowElement'
33-
children: BlockContent[]
34-
}
35-
36-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
37-
export interface MdxJsxTextElement extends MdxJsxElementFields, Parent {
38-
type: 'mdxJsxTextElement'
39-
children: PhrasingContent[]
40-
}
41-
42-
declare module 'mdast' {
43-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
44-
interface StaticPhrasingContentMap {
45-
mdxJsxTextElement: MdxJsxTextElement
46-
}
47-
48-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
49-
interface BlockContentMap {
50-
mdxJsxFlowElement: MdxJsxFlowElement
51-
}
52-
}
53-
54-
declare module 'hast' {
55-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
56-
interface RootContentMap {
57-
mdxJsxTextElement: MdxJsxTextElement
58-
mdxJsxFlowElement: MdxJsxFlowElement
59-
}
60-
61-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
62-
interface ElementContentMap {
63-
mdxJsxTextElement: MdxJsxTextElement
64-
mdxJsxFlowElement: MdxJsxFlowElement
65-
}
66-
}
1+
// To do: next major: remove this file.
2+
export type {
3+
MdxJsxAttributeValueExpression,
4+
MdxJsxAttribute,
5+
MdxJsxExpressionAttribute,
6+
MdxJsxFlowElement,
7+
MdxJsxTextElement,
8+
ToMarkdownOptions
9+
} from '../index.js'
10+
11+
/// <reference types="../index.js" />

lib/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
1313
* @typedef {import('mdast-util-to-markdown').Map} ToMarkdownMap
1414
*
15-
* @typedef {import('./complex-types.js').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
16-
* @typedef {import('./complex-types.js').MdxJsxAttribute} MdxJsxAttribute
17-
* @typedef {import('./complex-types.js').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute
18-
* @typedef {import('./complex-types.js').MdxJsxFlowElement} MdxJsxFlowElement
19-
* @typedef {import('./complex-types.js').MdxJsxTextElement} MdxJsxTextElement
15+
* @typedef {import('../index.js').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
16+
* @typedef {import('../index.js').MdxJsxAttribute} MdxJsxAttribute
17+
* @typedef {import('../index.js').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute
18+
* @typedef {import('../index.js').MdxJsxFlowElement} MdxJsxFlowElement
19+
* @typedef {import('../index.js').MdxJsxTextElement} MdxJsxTextElement
2020
*/
2121

2222
/**

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["**/*.js"],
2+
"include": ["**/*.js", "lib/complex-types.d.ts", "index.d.ts"],
33
"exclude": ["coverage/", "node_modules/"],
44
"compilerOptions": {
55
"checkJs": true,

0 commit comments

Comments
 (0)