pusher / pusher-js

Pusher Javascript library
http://pusher.com
MIT License
2.1k stars 370 forks source link

Incorrect TypeScript types for class with `moduleResolution: "nodeNext"` #791

Open tobimori opened 8 months ago

tobimori commented 8 months ago

Do you want to request a feature or report a bug? bug

What is the current behavior?

CleanShot 2024-01-05 at 14 07 45@2x

import Pusher from "pusher-js"
const pusher = new Pusher("APP_KEY", { cluster: "eu" })

tsconfig

{
  "include": ["**/*.ts", "**/*.tsx"],
  "compilerOptions": {
    "lib": ["DOM", "DOM.Iterable", "ES2022"],
    "isolatedModules": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "resolveJsonModule": true,
    "target": "ES2022",
    "strict": true,
    "noImplicitAny": true,
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./app/*"],
      "@/components": ["app/components/index.ts"],
      "@/state": ["app/utils/state/index.ts"],
      "@/icon-name": ["types/icon-name.d.ts"]
    },
    "skipLibCheck": true,
    "allowImportingTsExtensions": true,
    "noEmit": true
  }
}

What is the expected behavior?

TypeScript would detect te class as expected.

Which versions of Pusher, and which browsers / OS are affected by this issue? Did this work in previous versions of Pusher? If so, which? tested with 8.4, 8.3, 7.6;

tobimori commented 8 months ago

Works fine when removing moduleResolution: "NodeNext"

discapes commented 7 months ago

Workaround is adding a pusher-js.d.ts file:

declare module "pusher-js" {
    import p from "pusher-js/index.js";
    export default p.default;
}