triggerdotdev / trigger.dev

Trigger.dev is the open source background jobs platform.
https://trigger.dev/changelog
Apache License 2.0
8.16k stars 485 forks source link

bug: Typescript typedef errors in v3 SDK #1221

Open pangolingo opened 1 month ago

pangolingo commented 1 month ago

Provide environment information

System: OS: macOS 12.7.5 CPU: (10) arm64 Apple M1 Pro Memory: 75.05 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 20.7.0 - ~/.asdf/installs/nodejs/20.7.0/bin/node Yarn: 1.22.19 - ~/.asdf/installs/nodejs/20.7.0/bin/yarn npm: 10.1.0 - ~/.asdf/plugins/nodejs/shims/npm Watchman: 2024.04.08.00 - /opt/homebrew/bin/watchman

Describe the bug

Using version "@trigger.dev/sdk": "3.0.0-beta.48"

When I import anything (like task: import { task } from '@trigger.dev/sdk/v3';) from the SDK, my Typescript compiler picks up errors in the SDK's Typedefs file ad node_modules/@trigger.dev/sdk/dist/v3/index.d.ts.

 npx tsc -noEmit

node_modules/@trigger.dev/sdk/dist/v3/index.d.ts:173:40 - error TS2536: Type 'K' cannot be used to index type 'TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{ status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | ... 6 more ... | "EXPIRED"; ... 23 more ...; expiredAt?: Date | undefined; }, "output"> & { ...; } : Omit<...> & { ...; }'.

173 }) extends infer T ? { [K in keyof T]: (TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174     status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
270     output?: TRunHandle | undefined;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
271 })[K]; } : never>;
    ~~~~~

node_modules/@trigger.dev/sdk/dist/v3/index.d.ts:898:63 - error TS2693: 'CreateEnvironmentVariableParams' only refers to a type, but is being used as a value here.

898 declare const envvars_CreateEnvironmentVariableParams: typeof CreateEnvironmentVariableParams;
                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@trigger.dev/sdk/dist/v3/index.d.ts:899:64 - error TS2693: 'ImportEnvironmentVariablesParams' only refers to a type, but is being used as a value here.

899 declare const envvars_ImportEnvironmentVariablesParams: typeof ImportEnvironmentVariablesParams;
                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 3 errors in the same file, starting at: node_modules/@trigger.dev/sdk/dist/v3/index.d.ts:173

Here's my Typescript configuration

{
  "ts-node": {
    "files": true
  },
  "files": ["src/global.d.ts"],
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "strict": true,
    "noImplicitAny": false,
    "resolveJsonModule": true
  },
  "include": ["src/**/*"],
  "exclude": ["./node_modules"]
}

Reproduction repo

-

To reproduce

Set up a Node project with the included Typescript config. Import something from the SDK.

Additional information

Additionally when importing from the SDK, my linter cannot resolve the module, even though Typescript can. I get around that by disabling a rule. I'm not sure if this is related to the main issue.

// eslint-disable-next-line import/no-unresolved
import { logger, task } from '@trigger.dev/sdk/v3';

Error: Unable to resolve path to module '@trigger.dev/sdk/v3'. eslint(import/no-unresolved)

pangolingo commented 1 month ago

Reproduction: https://replit.com/@DaveIverson/TemptingWellwornProfiler#tsconfig.json Run npx tsc -noEmit in the Replit terminal. You should see the TS errors. In this Replit, the only change I made to the tsconfig.json file from Replit defaults is changing skipLibCheck to false.

I can work around this error by changing skipLibCheck to true, but that will also skip other typedefs that I want checked.