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

All types are any when using ESM #1653

Closed
2 of 4 tasks
danilofuchs opened this issue Nov 27, 2024 · 6 comments
Closed
2 of 4 tasks

All types are any when using ESM #1653

danilofuchs opened this issue Nov 27, 2024 · 6 comments

Comments

@danilofuchs
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Using inversify 6.1.4 in an ESM project leads to all types being any, as the imports in the .d.ts files do not contain .js extensions:
image

Adding .js manually fixes the types:
image

Steps to reproduce

Typescript 5.7.2

tsconfig.json:

{
  "extends": "./node_modules/@tsconfig/node22/tsconfig.json",

  "ts-node": {
    "files": true,
    "transpileOnly": true,
    "esm": true,
    "swc": true,
    "compilerOptions": {
      "module": "Node16",
      "moduleResolution": "Node16"
    }
  },

  "compilerOptions": {
    "lib": ["es2023"],
    "target": "es2022",
    "types": ["reflect-metadata"],
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,

    "preserveConstEnums": true,

    "noImplicitAny": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    "noFallthroughCasesInSwitch": true,

    "useUnknownInCatchVariables": false,

    "outDir": "build",

    "esModuleInterop": true,

    "module": "Node16",
    "moduleResolution": "Node16",

    "baseUrl": ".",
    "paths": {
      "~/*": ["./src/*"],
      "test/*": ["./test/*"]
    }
  }
}

Expected behavior

Types should work correctly

Possible solution

No response

Package version

6.1.4

Node.js version

22.11.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Stack trace

No response

Other

No response

@notaphplover
Copy link
Member

notaphplover commented Nov 27, 2024

Hey @danilofuchs, please provide a minimum reproduction code via code sandbox or any other platform. A reproduction repository is another valid choice.

Edit: Ok, I just recreated it, on my way to have it a look and fix it
Edit: Ok, I just had a look at the issue, it's not a bug.

Basically, you are using an esm project with a cjs typescript config:

{
  // ...
  "compilerOptions": {
    // ...
    "module": "Node16",
    "moduleResolution": "Node16",
    // ...
  }
}

If you're working on an ESM context you need to have a proper ESM typescript config:

{
  // ...
  "compilerOptions": {
    // ...
    "module": "ES2022",
    "moduleResolution": "Bundler",
    // ...
  }
}

Closing the issue now. If you think this is a typing issue, please provide a recreation code as I asked and I'll reopen the issue.

@notaphplover
Copy link
Member

After some consideration (thanks @alecgibson), I double checked docs and realized this is indeed a bug. I should be able to fix this tomorrow. Reopening the issue

@notaphplover notaphplover reopened this Nov 28, 2024
@notaphplover notaphplover mentioned this issue Nov 28, 2024
11 tasks
@notaphplover
Copy link
Member

Hey @danilofuchs, @alecgibson, I just released [email protected] which seems to fix this issue. Could you double check it please? Thanks in advance

@alecgibson
Copy link

Sent this on Discord, but also putting here to increase visibility:

Can confirm:

../node_modules/inversify/lib/esm/index.d.ts:350:34 - error TS2315: Type 'ServiceIdentifier' is not generic.

350     getAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T[];

Where digging into the definitions shows this:

Type alias 'ServiceIdentifier' circularly references itself.ts(2456)

And I notice it's both:

  • imported from @inversifyjs/common on line 1; and
  • redefined circularly referencing itself with shadowing on line 74 (same with Newable)

I suspect you just need to rename or namespace the import from @inversifyjs/common

@notaphplover
Copy link
Member

Hey @alecgibson, [email protected] should solve the issue 😃

@danilofuchs
Copy link
Author

I can confirm [email protected] fixes this issue for me!

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

3 participants