diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c21812da6..2d985cfc6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -86,4 +86,4 @@ jobs: - name: Lint run: npm run lint - name: Lint Types - run: npm run dtslint + run: npm run tsd diff --git a/CHANGELOG.md b/CHANGELOG.md index 420079d7b..03d9d2732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This release notably changes to using N-API. 🎉 * Avoid calling virtual methods in constructors/destructors to avoid bypassing virtual dispatch. (#2229) * Remove unused private field `backend` in the `Backend` class. (#2229) * Add Node.js v20 to CI. (#2237) +* Replaced `dtslint` with `tsd` (#2313) ### Added * Added string tags to support class detection ### Fixed diff --git a/types/index.d.ts b/index.d.ts similarity index 100% rename from types/index.d.ts rename to index.d.ts diff --git a/types/test.ts b/index.test-d.ts similarity index 50% rename from types/test.ts rename to index.test-d.ts index b48c78011..86e8dfc28 100644 --- a/types/test.ts +++ b/index.test-d.ts @@ -1,5 +1,8 @@ -import * as Canvas from 'canvas' -import * as path from "path"; +import { expectAssignable, expectType } from 'tsd' +import * as path from 'path' +import { Readable } from 'stream' + +import * as Canvas from './index' Canvas.registerFont(path.join(__dirname, '../pfennigFont/Pfennig.ttf'), {family: 'pfennigFont'}) @@ -13,34 +16,38 @@ canv.getContext('2d', {alpha: false}) // LHS is ImageData, not Canvas.ImageData const id = ctx.getImageData(0, 0, 10, 10) -const h: number = id.height +expectType(id.height) +expectType(id.width) ctx.currentTransform = ctx.getTransform() ctx.quality = 'best' ctx.textDrawingMode = 'glyph' -const grad: Canvas.CanvasGradient = ctx.createLinearGradient(0, 1, 2, 3) +const grad = ctx.createLinearGradient(0, 1, 2, 3) +expectType(grad) grad.addColorStop(0.1, 'red') const dm = new Canvas.DOMMatrix([1, 2, 3, 4, 5, 6]) -const a: number = dm.a +expectType(dm.a) -const b1: Buffer = canv.toBuffer() -canv.toBuffer("application/pdf") -canv.toBuffer((err, data) => {}, "image/png") -canv.createJPEGStream({quality: 0.5}) -canv.createPDFStream({author: "octocat"}) +expectType(canv.toBuffer()) +expectType(canv.toBuffer('application/pdf')) +canv.toBuffer((err, data) => {}, 'image/png') +expectAssignable(canv.createJPEGStream({ quality: 0.5 })) +expectAssignable(canv.createPDFStream({ author: 'octocat' })) canv.toDataURL() const img = new Canvas.Image() img.src = Buffer.alloc(0) img.dataMode = Canvas.Image.MODE_IMAGE | Canvas.Image.MODE_MIME img.onload = () => {} -img.onload = null; +img.onload = null -const id2: Canvas.ImageData = Canvas.createImageData(new Uint16Array(4), 1) +const id2 = Canvas.createImageData(new Uint16Array(4), 1) +expectType(id2) +ctx.putImageData(id2, 0, 0) ctx.drawImage(canv, 0, 0) -Canvas.deregisterAllFonts(); +Canvas.deregisterAllFonts() diff --git a/package.json b/package.json index 828d377b5..12b9be365 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "author": "TJ Holowaychuk ", "main": "index.js", "browser": "browser.js", + "types": "index.d.ts", "contributors": [ "Nathan Rajlich ", "Rod Vagg ", @@ -32,7 +33,7 @@ "generate-wpt": "node ./test/wpt/generate.js", "test-wpt": "mocha test/wpt/generated/*.js", "install": "node-pre-gyp install --fallback-to-build --update-binary", - "dtslint": "dtslint types" + "tsd": "tsd" }, "binary": { "module_name": "canvas", @@ -43,12 +44,13 @@ }, "files": [ "binding.gyp", + "browser.js", + "index.d.ts", + "index.js", "lib/", "src/", - "util/", - "types/index.d.ts" + "util/" ], - "types": "types/index.d.ts", "dependencies": { "@mapbox/node-pre-gyp": "^1.0.0", "node-addon-api": "^7.0.0", @@ -57,12 +59,12 @@ "devDependencies": { "@types/node": "^10.12.18", "assert-rejects": "^1.0.0", - "dtslint": "^4.0.7", "express": "^4.16.3", "js-yaml": "^4.1.0", "mocha": "^5.2.0", "pixelmatch": "^4.0.2", "standard": "^12.0.1", + "tsd": "^0.29.0", "typescript": "^4.2.2" }, "engines": { diff --git a/types/Readme.md b/types/Readme.md deleted file mode 100644 index 4beb7f528..000000000 --- a/types/Readme.md +++ /dev/null @@ -1,3 +0,0 @@ -Notes: - -* `"unified-signatures": false` because of https://github.com/Microsoft/dtslint/issues/183 diff --git a/types/tsconfig.json b/types/tsconfig.json deleted file mode 100644 index 226482c23..000000000 --- a/types/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": ["es6"], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "noEmit": true, - "baseUrl": ".", - "paths": { "canvas": ["."] } - } -} diff --git a/types/tslint.json b/types/tslint.json deleted file mode 100644 index 64e2a316f..000000000 --- a/types/tslint.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "dtslint/dtslint.json", - "rules": { - "semicolon": false, - "unified-signatures": false - } -}