Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Typescript typedef errors in v3 SDK #1221

Open
pangolingo opened this issue Jul 16, 2024 · 1 comment
Open

bug: Typescript typedef errors in v3 SDK #1221

pangolingo opened this issue Jul 16, 2024 · 1 comment

Comments

@pangolingo
Copy link

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant