From a90931123b5a9ba16c9d8b89183d90560170ca52 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Mon, 9 Nov 2020 15:28:29 -0700 Subject: [PATCH 1/4] types: add typescript typings for mdast-util-to-string --- package.json | 9 ++++++--- types/index.d.ts | 8 ++++++++ types/test.ts | 4 ++++ types/tsconfig.json | 15 +++++++++++++++ types/tslint.json | 7 +++++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 types/index.d.ts create mode 100644 types/test.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/package.json b/package.json index a41ff13..c561f69 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, diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..51d7229 --- /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): string + +export = mdastToString diff --git a/types/test.ts b/types/test.ts new file mode 100644 index 0000000..cabc6bb --- /dev/null +++ b/types/test.ts @@ -0,0 +1,4 @@ +import mdastUtilToString = require('mdast-util-to-string') + +mdastUtilToString() // $ExpectError +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 + } +} From 652d8f7fc3209ed14dbf6acdbc78047e02685998 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Tue, 10 Nov 2020 06:12:23 -0700 Subject: [PATCH 2/4] types: also support list of nodes --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 51d7229..39b41db 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,6 +3,6 @@ import {Node} from 'unist' declare namespace mdastToString {} -declare function mdastToString(node: Node): string +declare function mdastToString(node: Node | Node[]): string export = mdastToString From b1322480bcbccf7d41e55cce32c15dd94ad0dff9 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Tue, 10 Nov 2020 07:21:38 -0700 Subject: [PATCH 3/4] types: test star import --- types/test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/test.ts b/types/test.ts index cabc6bb..2d7d7ad 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,4 +1,5 @@ -import mdastUtilToString = require('mdast-util-to-string') +import * as mdastUtilToString from 'mdast-util-to-string' mdastUtilToString() // $ExpectError mdastUtilToString({type: 'root'}) // $ExpectType string +mdastUtilToString([{type: 'root'}]) // $ExpectType string From ced6173c3f04e6c8b56d87eb470912ab8e59e2a8 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Tue, 10 Nov 2020 10:44:49 -0700 Subject: [PATCH 4/4] build: xo ignore type tests --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c561f69..5beb719 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,8 @@ "prettier": true, "esnext": false, "ignore": [ - "mdast-util-to-string.js" + "mdast-util-to-string.js", + "types/test.ts" ] }, "nyc": {