Skip to content

Commit 1fed227

Browse files
Introduced tstyche for type checking and to guard against unintentional API changes. For example, a test like this would have caught #3006 (#3020)
1 parent 9428e7c commit 1fed227

5 files changed

Lines changed: 90 additions & 35 deletions

File tree

.monorepolint.config.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const MAIN_PACKAGE = "@turf/turf";
1717

1818
const TAPE_PACKAGES = []; // projects that have tape tests
1919
const TYPES_PACKAGES = []; // projects that have types tests
20+
const TSTYCHE_PACKAGES = []; // projects that use tstyche for type tests.
2021
const BENCH_PACKAGES = []; // projects that have benchmarks
2122

2223
// iterate all the packages and figure out what buckets everything falls into
@@ -39,6 +40,10 @@ glob.sync(path.join(__dirname, "packages", "turf-*")).forEach((pk) => {
3940
if (fs.existsSync(path.join(pk, "types.ts"))) {
4041
TYPES_PACKAGES.push(name);
4142
}
43+
44+
if (fs.existsSync(path.join(pk, "test/types.tst.ts"))) {
45+
TSTYCHE_PACKAGES.push(name);
46+
}
4247
});
4348

4449
const TS_TAPE_PACKAGES = TAPE_PACKAGES.filter(
@@ -216,6 +221,15 @@ export default {
216221
includePackages: TYPES_PACKAGES,
217222
}),
218223

224+
packageScript({
225+
options: {
226+
scripts: {
227+
"test:types": "tstyche",
228+
},
229+
},
230+
includePackages: TSTYCHE_PACKAGES,
231+
}),
232+
219233
requireDependency({
220234
options: {
221235
devDependencies: {
@@ -242,6 +256,15 @@ export default {
242256
includePackages: TS_PACKAGES,
243257
}),
244258

259+
requireDependency({
260+
options: {
261+
devDependencies: {
262+
tstyche: "^6.2.0",
263+
},
264+
},
265+
includePackages: TSTYCHE_PACKAGES,
266+
}),
267+
245268
requireDependency({
246269
options: {
247270
dependencies: {

packages/turf-line-offset/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"docs": "tsx ../../scripts/generate-readmes.ts",
5555
"test": "pnpm run /test:.*/",
5656
"test:tape": "tsx test.ts",
57-
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
57+
"test:types": "tstyche"
5858
},
5959
"devDependencies": {
6060
"@turf/truncate": "workspace:*",
@@ -63,6 +63,7 @@
6363
"benchmark": "^2.1.4",
6464
"load-json-file": "^7.0.1",
6565
"tape": "^5.9.0",
66+
"tstyche": "^6.2.0",
6667
"tsup": "^8.4.0",
6768
"tsx": "^4.19.4",
6869
"typescript": "^5.8.3",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { lineOffset } from "../index.js";
2+
import { lineString, multiLineString } from "@turf/helpers";
3+
import type { Feature, LineString, MultiLineString } from "geojson";
4+
5+
import { expect } from "tstyche";
6+
7+
const line = lineString([
8+
[0, 0],
9+
[10, 10],
10+
]);
11+
const multiLine = multiLineString([
12+
[
13+
[0, 0],
14+
[10, 10],
15+
],
16+
[
17+
[5, 5],
18+
[15, 15],
19+
],
20+
]);
21+
22+
/**
23+
* If the syntax below starts generating errors it's possible you've narrowed
24+
* the input arguments which is likely to be a breaking change.
25+
*/
26+
expect(lineOffset).type.toBeCallableWith(line, 50);
27+
expect(lineOffset).type.toBeCallableWith(line.geometry, 50);
28+
expect(lineOffset).type.toBeCallableWith(multiLine, 50);
29+
expect(lineOffset).type.toBeCallableWith(multiLine.geometry, 50);
30+
expect(lineOffset).type.toBeCallableWith(line, 50, { units: "miles" });
31+
32+
/**
33+
* If the sytax in this section starts generating errors, it's possible you've
34+
* broadened the return type which is likely to be a breaking change.
35+
*/
36+
expect(lineOffset(line, 50)).type.toBe<Feature<LineString>>();
37+
expect(lineOffset(multiLine, 50)).type.toBe<Feature<MultiLineString>>();

packages/turf-line-offset/types.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 28 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)