Skip to content

Commit 78b1e09

Browse files
committed
feat: fix types and use tsd
1 parent f2dc40d commit 78b1e09

File tree

7 files changed

+40
-226
lines changed

7 files changed

+40
-226
lines changed

.xo-config.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,34 @@ module.exports = {
1515
'unicorn/prefer-logical-operator-over-ternary': 'warn'
1616
},
1717
overrides: [
18+
{
19+
files: '**/*.mjs',
20+
parserOptions: {
21+
sourceType: 'module'
22+
}
23+
},
1824
{
1925
files: 'test/jobs/*.js',
2026
rules: {
2127
'unicorn/no-process-exit': 'off'
2228
}
2329
},
2430
{
25-
files: ['*.ts', '**/*.ts'],
26-
parserOptions: {
27-
project: 'types/tsconfig.json'
28-
},
31+
files: ['**/*.d.ts'],
32+
rules: {
33+
'no-unused-vars': 'off',
34+
'@typescript-eslint/naming-convention': 'off',
35+
'no-redeclare': 'off',
36+
'@typescript-eslint/no-redeclare': 'off'
37+
}
38+
},
39+
{
40+
files: ['**/*.test-d.ts'],
2941
rules: {
30-
'no-redeclare': 'warn',
31-
'no-unused-vars': 'warn',
32-
'@typescript-eslint/no-unsafe-assignment': 'warn',
33-
'@typescript-eslint/no-unsafe-call': 'warn',
34-
'@typescript-eslint/no-unused-vars': 'warn',
35-
'@typescript-eslint/no-empty-function': 'warn',
36-
'@typescript-eslint/consistent-type-definitions': 'off',
37-
'@typescript-eslint/consistent-type-imports': 'off'
42+
'@typescript-eslint/no-unsafe-call': 'off',
43+
'@typescript-eslint/no-confusing-void-expression': 'off', // Conflicts with `expectError` assertion.
44+
'@typescript-eslint/no-unsafe-assignment': 'off'
3845
}
3946
}
40-
],
41-
parser: '@typescript-eslint/parser'
47+
]
4248
};

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
"node": ">=12.17.0 <13.0.0-0||>=13.2.0"
5353
},
5454
"files": [
55-
"src",
56-
"types"
55+
"src"
5756
],
5857
"homepage": "https://github.com/breejs/bree",
5958
"keywords": [
@@ -157,5 +156,5 @@
157156
"test": "npm run ava && tsd",
158157
"test-coverage": "cross-env NODE_ENV=test nyc npm run test"
159158
},
160-
"types": "types"
159+
"types": "src/index.d.ts"
161160
}

types/index.d.ts renamed to src/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Definitions by: Taylor Schley <https://github.com/shadowgate15>
22

33
import { EventEmitter } from 'node:events';
4-
import { WorkerOptions, Worker } from 'node:worker_threads';
5-
import { Timeout, Interval } from 'safe-timers';
4+
import { type WorkerOptions, type Worker } from 'node:worker_threads';
5+
import { type Timeout, type Interval } from 'safe-timers';
66

77
export = Bree;
88

@@ -68,7 +68,7 @@ declare class Bree extends EventEmitter {
6868
}
6969

7070
declare namespace Bree {
71-
interface Job {
71+
type Job = {
7272
name: string;
7373
path: string | (() => void);
7474
timeout: number | string | boolean;
@@ -81,11 +81,11 @@ declare namespace Bree {
8181
worker?: Partial<WorkerOptions>;
8282
outputWorkerMetadata?: boolean;
8383
timezone?: string;
84-
}
84+
};
8585

8686
type JobOptions = Required<Pick<Job, 'name'>> & Partial<Omit<Job, 'name'>>;
8787

88-
interface BreeConfigs {
88+
type BreeConfigs = {
8989
logger: BreeLogger | boolean;
9090
root: string | boolean;
9191
silenceRootCheckError: boolean;
@@ -105,7 +105,7 @@ declare namespace Bree {
105105
errorHandler?: (error: any, workerMetadata: any) => void;
106106
workerMessageHandler?: (message: any, workerMetadata: any) => void;
107107
outputWorkerMetadata: boolean;
108-
}
108+
};
109109

110110
type BreeOptions = Partial<Omit<BreeConfigs, 'jobs'>> & {
111111
jobs?: Array<string | (() => void) | JobOptions>;
@@ -115,9 +115,9 @@ declare namespace Bree {
115115

116116
function extend<T = unknown>(plugin: PluginFunc<T>, options?: T): Bree;
117117

118-
interface BreeLogger {
118+
type BreeLogger = {
119119
info: (...args: any[]) => any;
120120
warn: (...args: any[]) => any;
121121
error: (...args: any[]) => any;
122-
}
122+
};
123123
}

test-d/index.test-d.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { expectType, expectNotType } from 'tsd';
2-
import Bree from '..';
1+
import { expectType } from 'tsd';
2+
import Bree from '../src';
33

44
const bree = new Bree({});
55

6-
expectType<Bree.Constructor>(Bree);
7-
expectType<Bree.Bree>(bree);
6+
expectType<Bree>(bree);
7+
8+
expectType<Bree['start']>(bree.start);
9+
expectType<Bree['stop']>(bree.stop);
10+
expectType<Bree['run']>(bree.run);
11+
expectType<Bree['add']>(bree.add);
12+
expectType<Bree['remove']>(bree.remove);
13+
expectType<Bree['createWorker']>(bree.createWorker);

types/tests.ts

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

types/tsconfig.json

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

types/tslint.json

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

0 commit comments

Comments
 (0)