Skip to content

Commit 541d7b2

Browse files
fix: export type TaskFunction & TaskInnerApi (#2)
1 parent 7bef7ff commit 541d7b2

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"scripts": {
2525
"lint": "eslint .",
2626
"test": "jest",
27-
"typecheck": "tsc --noEmit",
27+
"typecheck": "tsc --noEmit && :",
2828
"build": "rm -rf dist && tsup src/index.ts --dts --minify --no-splitting --external 'yoga-layout-prebuilt'"
2929
},
3030
"husky": {

src/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,35 @@ const createTaskInnerApi = (taskState: TaskObject) => {
3636
return api;
3737
};
3838

39-
type TaskFunction = (taskHelpers: ReturnType<typeof createTaskInnerApi>) => Promise<unknown>;
39+
// Until full ESM
40+
// eslint-disable-next-line @typescript-eslint/no-namespace
41+
namespace task {
42+
export type TaskInnerApi = ReturnType<typeof createTaskInnerApi>;
43+
export type TaskFunction = (taskHelpers: TaskInnerApi) => Promise<unknown>;
44+
}
4045

41-
type TaskAPI<T extends TaskFunction> = {
46+
type TaskApi<T extends task.TaskFunction> = {
4247
run: () => Promise<Awaited<ReturnType<T>>>;
4348
clear: () => void;
4449
};
4550
type TaskResults<
46-
T extends TaskFunction,
47-
Tasks extends TaskAPI<T>[]
51+
T extends task.TaskFunction,
52+
Tasks extends TaskApi<T>[]
4853
> = {
4954
[key in keyof Tasks]: (
50-
Tasks[key] extends TaskAPI<T>
55+
Tasks[key] extends TaskApi<T>
5156
? Awaited<ReturnType<Tasks[key]['run']>>
5257
: Tasks[key]
5358
);
5459
};
5560

5661
let app: ReturnType<typeof createApp>;
5762

58-
function registerTask<T extends TaskFunction>(
63+
function registerTask<T extends task.TaskFunction>(
5964
taskList: TaskList,
6065
taskTitle: string,
6166
taskFunction: T,
62-
): TaskAPI<T> {
67+
): TaskApi<T> {
6368
if (!app) {
6469
app = createApp(taskList);
6570
taskList.isRoot = true;
@@ -105,7 +110,7 @@ function registerTask<T extends TaskFunction>(
105110
function createTaskFunction(
106111
taskList: TaskList,
107112
) {
108-
async function task<T extends TaskFunction>(
113+
async function task<T extends task.TaskFunction>(
109114
title: string,
110115
taskFunction: T,
111116
) {
@@ -118,7 +123,7 @@ function createTaskFunction(
118123
);
119124
}
120125

121-
const createTask = <T extends TaskFunction>(
126+
const createTask = <T extends task.TaskFunction>(
122127
title: string,
123128
taskFunction: T,
124129
) => registerTask(
@@ -128,8 +133,8 @@ function createTaskFunction(
128133
);
129134

130135
task.group = async <
131-
T extends TaskFunction,
132-
Tasks extends TaskAPI<T>[]
136+
T extends task.TaskFunction,
137+
Tasks extends TaskApi<T>[]
133138
>(
134139
createTasks: (taskCreator: typeof createTask) => readonly [...Tasks],
135140
options?: Options,

0 commit comments

Comments
 (0)