khasanovbi / phaser3-rex-plugins-types

MIT License
15 stars 7 forks source link

TS2507: Type 'typeof EventEmitter' is not a constructor function type. on TS 4.6 #29

Open Nitorac opened 2 years ago

Nitorac commented 2 years ago

Hi, I have an issue when trying to tsc a project using @types/phaser3-rex-plugins-types.

Environment

Expected behavior

My project successfully compile with tsc

Actual behavior

At compile time, I have this error :

node_modules/phaser3-rex-plugins-types/@types/phaser3-rex-plugins/plugins/utils/eventemitter/EventEmitter.d.ts:4:101 - error TS2507: Type 'typeof EventEmitter' is not a constructor functi
on type.

4     export default class EventEmitter<EventTypes extends string | symbol = string | symbol> extends EE<EventTypes> {
                                                                                                      ~~

Found 1 error in node_modules/phaser3-rex-plugins-types/@types/phaser3-rex-plugins/plugins/utils/eventemitter/EventEmitter.d.ts:4

Possible fix

This fix makes my project compile again

--- a/@types/phaser3-rex-plugins/plugins/utils/eventemitter/EventEmitter.d.ts
+++ b/@types/phaser3-rex-plugins/plugins/utils/eventemitter/EventEmitter.d.ts
@@ -1,5 +1,5 @@
 declare module 'phaser3-rex-plugins/plugins/utils/eventemitter/EventEmitter' {
-    import * as EE from 'eventemitter3';
+    import { EventEmitter as EE }  from 'eventemitter3';

     export default class EventEmitter<EventTypes extends string | symbol = string | symbol> extends EE<EventTypes> {
         shutdown(): void;
khasanovbi commented 2 years ago

Hi @Nitorac, thanks for issue. I tried the same versions, but I did not find an error. Could you please also provide eventemitter3 version and your tsconfig.json? Maybe this issue related to moduleResolution setting.

Nitorac commented 2 years ago

As you said, I forgot to mention it's an ESM module project !

My eventemitter3 version is 4.0.7.

Here is my tsconfig.json :

{
    "compilerOptions": {
        "outDir": "dist",
        "rootDir": "src",
        "module": "esnext",
        "target": "esnext",
        "lib": [
          "esnext",
          "esnext.asynciterable",
          "dom",
          "scripthost"
        ],
        "strict": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "downlevelIteration": true,
        "noImplicitAny": true,
        "baseUrl": "./src",
        "forceConsistentCasingInFileNames": true,
        "paths": {
            "*": [
                "node_modules/"
            ],
            ...
        }
    },
    "include": [
         ...
        "node_modules/phaser3-rex-plugins-types"
    ],
    "exclude": [
         ...
    ]
}
khasanovbi commented 2 years ago

The problem is related to esModuleInterop config, I need some time to investigate this.

simonhvc commented 1 year ago

Has there been an update on this? Same error is happening on my end.