Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.

Commit eabcd4e

Browse files
Glazysindresorhus
authored andcommitted
Add TypeScript definition
Closes #11
1 parent b32fde6 commit eabcd4e

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

index.d.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Container } from "unstated";
2+
3+
declare const UNSTATED: {
4+
/**
5+
An object containing the project's containers.
6+
*/
7+
containers: {
8+
[containerName: string]: Container<{ [stateName: string]: unknown }>;
9+
};
10+
11+
/**
12+
Whether the debugger should be enabled or not.
13+
*/
14+
isEnabled: boolean;
15+
16+
/**
17+
Function that logs out the current state.
18+
*/
19+
logState: () => void;
20+
21+
/**
22+
Boolean value that represents whether state changes should be logged to the
23+
console.
24+
*/
25+
logStateChanges: boolean;
26+
27+
/**
28+
An object containing all of the state values.
29+
*/
30+
states: {
31+
[containerName: string]: { [stateName: string]: unknown };
32+
};
33+
};
34+
35+
export default UNSTATED;

index.test-d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expectType } from "tsd-check";
2+
import UNSTATED from "./index";
3+
import { Container } from "unstated";
4+
5+
expectType<boolean>(UNSTATED.isEnabled);
6+
expectType<boolean>(UNSTATED.logStateChanges);
7+
8+
expectType<{
9+
[containerName: string]: Container<{ [stateName: string]: unknown }>;
10+
}>(UNSTATED.containers);
11+
12+
expectType<() => void>(UNSTATED.logState);
13+
expectType<void>(UNSTATED.logState());
14+
15+
expectType<{ [containerName: string]: { [stateName: string]: unknown } }>(
16+
UNSTATED.states
17+
);

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd-check"
1717
},
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"index.d.ts"
2021
],
2122
"keywords": [
2223
"unstated",
@@ -38,6 +39,7 @@
3839
"ava": "*",
3940
"browser-env": "^3.2.5",
4041
"react": "^16.3.0",
42+
"tsd-check": "^0.6.0",
4143
"unstated": "^2.0.2",
4244
"xo": "*"
4345
},
@@ -48,6 +50,9 @@
4850
"envs": [
4951
"node",
5052
"browser"
53+
],
54+
"ignores": [
55+
"*.ts"
5156
]
5257
},
5358
"ava": {

0 commit comments

Comments
 (0)