diff --git a/package.json b/package.json index a41ff13..5beb719 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,13 @@ "Titus Wormer (https://wooorm.com)" ], "files": [ - "index.js" + "index.js", + "types/index.d.ts" ], - "dependencies": {}, + "types": "types/index.d.ts", "devDependencies": { "browserify": "^17.0.0", + "dtslint": "^4.0.0", "nyc": "^15.0.0", "prettier": "^2.0.0", "remark-cli": "^9.0.0", @@ -45,7 +47,8 @@ "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run build && npm run test-coverage" + "test-types": "dtslint types", + "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" }, "prettier": { "tabWidth": 2, @@ -59,7 +62,8 @@ "prettier": true, "esnext": false, "ignore": [ - "mdast-util-to-string.js" + "mdast-util-to-string.js", + "types/test.ts" ] }, "nyc": { diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..39b41db --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,8 @@ +// Minimum TypeScript Version: 3.0 +import {Node} from 'unist' + +declare namespace mdastToString {} + +declare function mdastToString(node: Node | Node[]): string + +export = mdastToString diff --git a/types/test.ts b/types/test.ts new file mode 100644 index 0000000..2d7d7ad --- /dev/null +++ b/types/test.ts @@ -0,0 +1,5 @@ +import * as mdastUtilToString from 'mdast-util-to-string' + +mdastUtilToString() // $ExpectError +mdastUtilToString({type: 'root'}) // $ExpectType string +mdastUtilToString([{type: 'root'}]) // $ExpectType string diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..28f4cd1 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "lib": [ + "ES5" + ], + "strict": true, + "baseUrl": ".", + "paths": { + "mdast-util-to-string": [ + "./index.d.ts" + ] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..b818924 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,7 @@ +{ +"extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "whitespace": false + } +}