Skip to content

Commit 63d4cd4

Browse files
committed
Replace dtslint with tsd
1 parent a5b379b commit 63d4cd4

File tree

8 files changed

+28
-42
lines changed

8 files changed

+28
-42
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ jobs:
8686
- name: Lint
8787
run: npm run lint
8888
- name: Lint Types
89-
run: npm run dtslint
89+
run: npm run tsd

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This release notably changes to using N-API. 🎉
2424
* Avoid calling virtual methods in constructors/destructors to avoid bypassing virtual dispatch. (#2229)
2525
* Remove unused private field `backend` in the `Backend` class. (#2229)
2626
* Add Node.js v20 to CI. (#2237)
27+
* Replaced `dtslint` with `tsd` (#2313)
2728
### Added
2829
* Added string tags to support class detection
2930
### Fixed

types/index.d.ts index.d.ts

File renamed without changes.

types/test.ts index.test-d.ts

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import * as Canvas from 'canvas'
2-
import * as path from "path";
1+
import { expectAssignable, expectType } from 'tsd'
2+
import * as path from 'path'
3+
import { Readable } from 'stream'
4+
5+
import * as Canvas from './index'
36

47
Canvas.registerFont(path.join(__dirname, '../pfennigFont/Pfennig.ttf'), {family: 'pfennigFont'})
58

@@ -13,34 +16,38 @@ canv.getContext('2d', {alpha: false})
1316

1417
// LHS is ImageData, not Canvas.ImageData
1518
const id = ctx.getImageData(0, 0, 10, 10)
16-
const h: number = id.height
19+
expectType<number>(id.height)
20+
expectType<number>(id.width)
1721

1822
ctx.currentTransform = ctx.getTransform()
1923

2024
ctx.quality = 'best'
2125
ctx.textDrawingMode = 'glyph'
2226

23-
const grad: Canvas.CanvasGradient = ctx.createLinearGradient(0, 1, 2, 3)
27+
const grad = ctx.createLinearGradient(0, 1, 2, 3)
28+
expectType<Canvas.CanvasGradient>(grad)
2429
grad.addColorStop(0.1, 'red')
2530

2631
const dm = new Canvas.DOMMatrix([1, 2, 3, 4, 5, 6])
27-
const a: number = dm.a
32+
expectType<number>(dm.a)
2833

29-
const b1: Buffer = canv.toBuffer()
30-
canv.toBuffer("application/pdf")
31-
canv.toBuffer((err, data) => {}, "image/png")
32-
canv.createJPEGStream({quality: 0.5})
33-
canv.createPDFStream({author: "octocat"})
34+
expectType<Buffer>(canv.toBuffer())
35+
expectType<Buffer>(canv.toBuffer('application/pdf'))
36+
canv.toBuffer((err, data) => {}, 'image/png')
37+
expectAssignable<Readable>(canv.createJPEGStream({ quality: 0.5 }))
38+
expectAssignable<Readable>(canv.createPDFStream({ author: 'octocat' }))
3439
canv.toDataURL()
3540

3641
const img = new Canvas.Image()
3742
img.src = Buffer.alloc(0)
3843
img.dataMode = Canvas.Image.MODE_IMAGE | Canvas.Image.MODE_MIME
3944
img.onload = () => {}
40-
img.onload = null;
45+
img.onload = null
4146

42-
const id2: Canvas.ImageData = Canvas.createImageData(new Uint16Array(4), 1)
47+
const id2 = Canvas.createImageData(new Uint16Array(4), 1)
48+
expectType<Canvas.ImageData>(id2)
49+
ctx.putImageData(id2, 0, 0)
4350

4451
ctx.drawImage(canv, 0, 0)
4552

46-
Canvas.deregisterAllFonts();
53+
Canvas.deregisterAllFonts()

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "TJ Holowaychuk <[email protected]>",
66
"main": "index.js",
77
"browser": "browser.js",
8+
"types": "index.d.ts",
89
"contributors": [
910
"Nathan Rajlich <[email protected]>",
1011
"Rod Vagg <[email protected]>",
@@ -32,7 +33,7 @@
3233
"generate-wpt": "node ./test/wpt/generate.js",
3334
"test-wpt": "mocha test/wpt/generated/*.js",
3435
"install": "node-pre-gyp install --fallback-to-build --update-binary",
35-
"dtslint": "dtslint types"
36+
"tsd": "tsd"
3637
},
3738
"binary": {
3839
"module_name": "canvas",
@@ -43,12 +44,12 @@
4344
},
4445
"files": [
4546
"binding.gyp",
47+
"index.d.ts",
48+
"index.js",
4649
"lib/",
4750
"src/",
48-
"util/",
49-
"types/index.d.ts"
51+
"util/"
5052
],
51-
"types": "types/index.d.ts",
5253
"dependencies": {
5354
"@mapbox/node-pre-gyp": "^1.0.0",
5455
"node-addon-api": "^7.0.0",
@@ -57,12 +58,12 @@
5758
"devDependencies": {
5859
"@types/node": "^10.12.18",
5960
"assert-rejects": "^1.0.0",
60-
"dtslint": "^4.0.7",
6161
"express": "^4.16.3",
6262
"js-yaml": "^4.1.0",
6363
"mocha": "^5.2.0",
6464
"pixelmatch": "^4.0.2",
6565
"standard": "^12.0.1",
66+
"tsd": "^0.29.0",
6667
"typescript": "^4.2.2"
6768
},
6869
"engines": {

types/Readme.md

-3
This file was deleted.

types/tsconfig.json

-13
This file was deleted.

types/tslint.json

-7
This file was deleted.

0 commit comments

Comments
 (0)