Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-needles-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-labs/task': patch
---

Disambiguate `TypeFunction` type to fix type error when providing a task function making use of the abort signal.
4 changes: 2 additions & 2 deletions packages/labs/task/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {notEqual} from '@lit/reactive-element';
import {ReactiveControllerHost} from '@lit/reactive-element/reactive-controller.js';

export interface TaskFunctionOptions {
signal?: AbortSignal;
signal: AbortSignal;
}

export type TaskFunction<D extends ReadonlyArray<unknown>, R = unknown> = (
args: D,
options?: TaskFunctionOptions
options: TaskFunctionOptions
) => R | typeof initialState | Promise<R | typeof initialState>;
export type ArgsFunction<D extends ReadonlyArray<unknown>> = () => D;

Expand Down
12 changes: 12 additions & 0 deletions packages/labs/task/src/test/task_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,18 @@ suite('Task', () => {
};
});

test('task functions can infer type of option param', () => {
return class MyElement extends ReactiveElement {
task = new Task(
this,
// Second param should get inferred to `TaskFunctionOptions` with an
// `AbortSignal`
([a], {signal}) => (signal.throwIfAborted(), a),
() => [1]
);
};
});

test('onComplete callback is called', async () => {
let numOnCompleteInvocations = 0;
let lastOnCompleteResult: string | undefined = undefined;
Expand Down