octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
6.83k stars 1k forks source link

[BUG]: Octokit v4 types #2677

Closed klippx closed 1 month ago

klippx commented 1 month ago

What happened?

TS does not seem to like the import("@octokit/core/types").Constructor or any such import, it resolves to any as you can see in the screenshot when I hover it:

Screenshot 2024-05-08 at 15 18 42

This causes my ts-eslint to panic Unsafe assignment of ananyvalue.eslint[@typescript-eslint/no-unsafe-assignment](https://typescript-eslint.io/rules/no-unsafe-assignment), but since it is opt-in most people might not even notice they start getting any all over the place.

My .eslintrc.js

module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended-type-checked',
    'plugin:@typescript-eslint/stylistic-type-checked',
    'plugin:import/errors',
    'plugin:import/typescript',
    'prettier',
  ],
  plugins: ['@typescript-eslint'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: true,
    tsconfigRootDir: __dirname,
  },
  root: true,
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.d.ts', '.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: {
        // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
        alwaysTryTypes: true,
        // Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
        project: '<root>/tsconfig.json',
      },
    },
  },
}

Related to #2676

Versions

Octokit.js 4.0.1

Relevant log output

No response

Code of Conduct

github-actions[bot] commented 1 month ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

wolfy1339 commented 1 month ago

What is your tsconfig?

gr2m commented 1 month ago

can you test again with the latest version? We had a build config bug that was resolved in v4.0.2

northword commented 1 month ago

seems stil:

image

image

my tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Node",
    "esModuleInterop": true,
    "strict": true,
    "resolveJsonModule": true,
    "declaration": true,
    "outDir": "dist",
    "skipLibCheck": true,
    "rootDir": "src"
  },
  "include": ["src", "types", "bin"]
}

Currently using 4.0.2, works fine on 3.1.2.

wolfy1339 commented 1 month ago

Please read up https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports and https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

This is an error with your tsconfig.json, you have to use either node16 or nodenext modules and moduleresolution

northword commented 1 month ago

Oh very sorry for taking up your time because of my problem, I made changes based on your suggestions and have fixed the problem, thanks!

wolfy1339 commented 1 month ago

The original author hasn't responded, and given that #2676 was resolved and that this seems like a case of misconfigured TypeScript, I will close this

klippx commented 1 month ago

Yes, my project was not correctly in ESM, not in terms of typescript. After applying NodeNext and absolute imports octokit works fine.