unused-task-signal
A useTask callback (@evobug_com/safe-ts-vue, @evobug_com/safe-ts-react), or a callback of std's latest (@evobug_com/safe-ts-std/async), that never reads its signal (no first parameter, or one that isn't used: _signal) and calls something that could take it. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
Why: a task aborts the previous run's signal when a new run starts and when its scope ends. A request that doesn't get the signal keeps running after that: the answer is thrown away, but the server still does the work and the connection stays open, and a GET that never answers has no time limit. Pass the signal on, to fetch or the request helper. Guide: Async state.
✕ Rejectedunused-task-signal
ts
import type { Enum } from "@evobug_com/safe-ts-std/enum";
import type { Result } from "@evobug_com/safe-ts-std/result";
import { useTask } from "@evobug_com/safe-ts-vue/task";
type RequestError = Enum<{ Offline: {}; Status: { status: number } }>;
declare function fetchUser(id: string, init?: { signal?: AbortSignal }): Promise<Result<string, RequestError>>;
export function useUser() {
return useTask((_signal, id: string) => fetchUser(id));
}✓ Accepted0 diagnostics
ts
import type { Enum } from "@evobug_com/safe-ts-std/enum";
import type { Result } from "@evobug_com/safe-ts-std/result";
import { useTask } from "@evobug_com/safe-ts-vue/task";
type RequestError = Enum<{ Offline: {}; Status: { status: number } }>;
declare function fetchUser(id: string, init?: { signal?: AbortSignal }): Promise<Result<string, RequestError>>;
export function useUser() {
return useTask((signal, id: string) => fetchUser(id, { signal }));
}What could take the signal. The checker reads the declaration of each function the task calls by name, in the same file, a file it imports, or a package's types (.d.ts). One counts when a parameter is named signal, is typed AbortSignal or RequestInit, has a signal field written out (init?: { signal?: AbortSignal }), or is of a named type with a signal field (options: LoadOptions). fetch counts. So does every call the checker can't follow: a function it can't find, a function the task was given or declares inside, a method of an object (api.load()), a parameter of a type it can't read named like options (FetchInit, RequestOptions), and a parameter without a type named init, options or config, or ...args. Methods of arrays, promises and strings (then, map, ...) don't.
A task whose calls take no signal isn't reported: there is nothing to pass on. A navigation is one (vue-router):
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { push, useRouter } from "@evobug_com/safe-ts-feature-vue-router";
import { Match } from "@evobug_com/safe-ts-vue/match";
import { useTask } from "@evobug_com/safe-ts-vue/task";
const router = useRouter();
const { state, run: openSettings } = useTask(() => push(router, "/settings"));
</script>
<template>
<button @click="openSettings()">Settings</button>
<Match :value="state">
<template #Failed>Couldn't open the settings. Try again.</template>
<template #_></template>
</Match>
</template>A request made inside such a function, without a signal, is fetch-signal's: the function takes none, so the fix is to give it one.
Having nothing to pass the signal to doesn't make a run harmless, though: a run that changes state after an await (viewer.open = await readFile(name)) still does so when a newer run superseded it, after the newer one. That is superseded-task-write's, on by default and not idiomatic: return the value for the task to hold, or ask the signal after the await. The two rules tell one story: pass the signal to what can take it (this rule), and don't let a superseded run write (that one).
A request helper that shares identical GETs between callers can still share the ones without a signal; give it a time limit of its own for the rest. A task passed by a name nothing else reads (const load = async () => ...; useTask(load)) is read as if written there; one whose name is read elsewhere too, or that comes from another file, isn't looked into.