With-the-Ranks / Spoke

With the Rank's fork of Politics Rewired's fork of Spoke
GNU General Public License v3.0
0 stars 1 forks source link

Improve task typing compatibility with graphile worker payloads #14

Open ajohn25 opened 7 months ago

ajohn25 commented 7 months ago

Describe the bug From the Graphile Worker docs:

Graphile Worker is written in TypeScript. By default, for safety, payloads are typed as unknown since they may have been populated by out of date code, or even from other sources. This requires you to add a type guard or similar to ensure the payload conforms to what you expect. It can be convenient to declare the payload types up front to avoid this unknown, but doing so might be unsafe — please be sure to read the caveats below.

We currently declare the payload types within some specific tasks, without any additional code to let TypeScript know that this type narrowing is ok.

To Reproduce Steps to reproduce the behavior:

  1. Open a typed task such as handle-deliery-report.ts
  2. See an error like the following
Type '(payload: LogRecord, helpers: JobHelpers) => Promise<void>' is not assignable to type 'Task'.
  Types of parameters 'payload' and 'payload' are incompatible.
    Type 'unknown' is not assignable to type 'LogRecord'.ts(2322)

Expected behavior Proper typing so that TS won't complain 😁

Additional context See suggestions here https://worker.graphile.org/docs/typescript