Skip to content

Commit cb81cbb

Browse files
committed
Refactor to move types to index.d.ts
1 parent 1c2cb7b commit cb81cbb

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.DS_Store
2-
lib/**/*.d.ts
3-
test/**/*.d.ts
4-
index.d.ts
2+
*.d.ts
53
*.log
64
coverage/
75
node_modules/
86
yarn.lock
7+
!/complex-types.d.ts
8+
!/index.d.ts

complex-types.d.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
import type {Literal} from 'hast'
1+
// To do: next major: remove this file.
2+
export type {Raw} from './index.js'
23

3-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
4-
export interface Raw extends Literal {
5-
type: 'raw'
6-
}
7-
8-
declare module 'hast' {
9-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
10-
interface RootContentMap {
11-
raw: Raw
12-
}
13-
14-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
15-
interface ElementContentMap {
16-
raw: Raw
17-
}
18-
}
4+
/// <reference types="./index.js" />

index.d.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type {Literal} from 'hast'
2+
3+
// Expose types.
4+
export type {Options, Handler, Handlers, H} from './lib/index.js'
5+
6+
// Expose JS API.
7+
export {one, all} from './lib/traverse.js'
8+
export {defaultHandlers, toHast} from './lib/index.js'
9+
10+
// Expose node type.
11+
/**
12+
* Raw string of HTML embedded into HTML AST.
13+
*/
14+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
15+
export interface Raw extends Literal {
16+
/**
17+
* Node type.
18+
*/
19+
type: 'raw'
20+
}
21+
22+
// Register nodes in content.
23+
declare module 'hast' {
24+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
25+
interface RootContentMap {
26+
/**
27+
* Raw string of HTML embedded into HTML AST.
28+
*/
29+
raw: Raw
30+
}
31+
32+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
33+
interface ElementContentMap {
34+
/**
35+
* Raw string of HTML embedded into HTML AST.
36+
*/
37+
raw: Raw
38+
}
39+
}

index.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/**
2-
* @typedef {import('./lib/index.js').Options} Options
3-
* @typedef {import('./lib/index.js').Handler} Handler
4-
* @typedef {import('./lib/index.js').Handlers} Handlers
5-
* @typedef {import('./lib/index.js').H} H
6-
* @typedef {import('./complex-types.js').Raw} Raw
7-
*/
8-
1+
// Note: types exposed from `index.d.ts`.
92
export {one, all} from './lib/traverse.js'
103
export {defaultHandlers, toHast} from './lib/index.js'

tsconfig.json

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

0 commit comments

Comments
 (0)