Skip to content

Commit 2406f90

Browse files
committed
tests: use dtslint for testing type definitions
1 parent 6510edb commit 2406f90

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
},
1515
"license": "MIT",
1616
"files": [
17-
"index.js"
17+
"index.js",
18+
"types/index.d.ts"
1819
],
1920
"main": "index.js",
20-
"types": "split-string.d.ts",
21+
"types": "types/index.d.ts",
2122
"engines": {
2223
"node": ">=8.6"
2324
},
2425
"scripts": {
25-
"test": "nyc mocha"
26+
"test": "nyc mocha",
27+
"test:types": "dtslint types"
2628
},
2729
"devDependencies": {
30+
"dtslint": "^0.7.0",
2831
"gulp-format-md": "^1.0.0",
2932
"mocha": "^5.2.0",
3033
"nyc": "^12.0.2"
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
interface ASTNode {
1+
// TypeScript Version: 3.0
2+
3+
export interface ASTNode {
24
type: 'root' | 'bracket';
35
nodes: ASTNode[];
46
stash: string[];
57
}
68

7-
interface State {
9+
export interface State {
810
input: string;
911
separator: string;
1012
stack: ASTNode[];
@@ -14,7 +16,7 @@ interface State {
1416
next(): string;
1517
}
1618

17-
interface Options {
19+
export interface Options {
1820
brackets?: { [key: string]: string } | boolean;
1921
quotes?: string[] | boolean;
2022
separator?: string;
@@ -24,9 +26,7 @@ interface Options {
2426

2527
type SplitFunc = (state: State) => boolean;
2628

27-
declare function split(input: string): string[];
28-
declare function split(input: string, options: Options): string[];
29-
declare function split(input: string, fn: SplitFunc): string[];
29+
declare function split(input: string, options?: Options | SplitFunc): string[];
3030
declare function split(input: string, options: Options, fn: SplitFunc): string[];
3131

3232
export default split;

test/test.ts renamed to types/test.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Testing the TypeScript definitions for split-string.
33
*/
4-
import split from '../';
4+
import split, { State } from '.';
55

6-
function keep(value, state) {
6+
function keep(value: string, state: State) {
77
return value !== '\\' && (value !== '"' || state.prev() === '\\');
8-
};
8+
}
99

10-
function splitFunc(state) {
10+
function splitFunc(state: State) {
1111
console.log(state);
1212
return state.prev() === 'a';
1313
}
@@ -27,7 +27,8 @@ split('«a.b».⟨c.d⟩.[e.f]', {
2727
split('a.b.c.a.d.e', splitFunc);
2828
split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] }, splitFunc);
2929

30-
// should error
31-
split();
32-
split(splitFunc);
33-
split({ quotes: ['"'] });
30+
// Make sure invalid calls fail
31+
32+
split(); // $ExpectError
33+
split(splitFunc); // $ExpectError
34+
split({ quotes: ['"'] }); // $ExpectError

types/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["es6", "dom"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictNullChecks": true,
8+
"strictFunctionTypes": true,
9+
"noEmit": true
10+
}
11+
}

types/tslint.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"no-relative-import-in-test": false
5+
}
6+
}

0 commit comments

Comments
 (0)