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

TypeScript error when using "moduleResolution": "node16" #270

Closed
cedx opened this issue Jun 14, 2022 · 5 comments
Closed

TypeScript error when using "moduleResolution": "node16" #270

cedx opened this issue Jun 14, 2022 · 5 comments

Comments

@cedx
Copy link

cedx commented Jun 14, 2022

I've recently switched from "moduleResolution": "node" to "moduleResolution": "node16" in a project using this library. And I get TypeScript errors:

node_modules/istextorbinary/edition-es2019-esm/index.js:14:24 - error TS7006: Parameter 'filename' implicitly has an 'any' type.
14 export function isText(filename, buffer) {
                          ~~~~~~~~
node_modules/istextorbinary/edition-es2019-esm/index.js:14:34 - error TS7006: Parameter 'buffer' implicitly has an 'any' type.
14 export function isText(filename, buffer) {
                                    ~~~~~~
node_modules/istextorbinary/edition-es2019-esm/index.js:45:26 - error TS7006: Parameter 'filename' implicitly has an 'any' type.
45 export function isBinary(filename, buffer) {
                            ~~~~~~~~
node_modules/istextorbinary/edition-es2019-esm/index.js:45:36 - error TS7006: Parameter 'buffer' implicitly has an 'any' type.
[...]
Found 16 errors in the same file, starting at: node_modules/istextorbinary/edition-es2019-esm/index.js:14

It seems that when using node16 module resolution, the typings located in the compiled-types folder are not loaded anymore by the TypeScript compiler.

Cf. https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing
I guess that when we use an export map in a library, we must also add a types property to this export map...

Node.js 18.2.0, TypeScript 4.7.3, istextorbinary 6.0.0.

@balupton
Copy link
Member

balupton commented Aug 17, 2022

This change will need to be implemented in https://github.com/bevry/boundation which scaffolds the meta files across all bevry's projects.

In my 15 years of working in the tech industry, I've probably only earned about 150k, so I have no desire to do this asap, as there is no ROI for me.

A PR on boundation is welcome, which I can give publish access to the PR author.

@balupton
Copy link
Member

Boundation successfully updated this package and didn't encounter this error. Is it still a problem for you?

@cedx
Copy link
Author

cedx commented Nov 15, 2023

Thanks for your efforts. Unfortunately, I no longer use TypeScript (I replaced it with Haxe), so I don't know if this problem is still present.

But I suppose it is still here because I don't see the typings declared in the proper section of the package.json file.

"types": "./compiled-types/",
"exports": {
  "node": {
    "import": "./edition-es2019-esm/index.js",
    "default": "./index.cjs",
    "require": "./edition-es2022/index.js"
  },
  "browser": {
    "import": "./edition-browsers/index.js"
  }
}

types should be declared in the exports section. Something like:

"exports": {
  "node": {
    "types": "./compiled-types/",
    "import": "./edition-es2019-esm/index.js",
    "default": "./index.cjs",
    "require": "./edition-es2022/index.js"
  },
  "browser": {
    "types": "./compiled-types/",
    "import": "./edition-browsers/index.js"
  }
}

@balupton
Copy link
Member

balupton commented Nov 15, 2023

Ahh okay, now I understand. I'll roll this out in my current batch of automation work. Thanks for bringing this to my attention.

@balupton
Copy link
Member

balupton commented Nov 21, 2023

this should now be resolved with v8.2.0
7ceccaa#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519

shoutout to my GitHub Sponsors for affording me the time to make this happen

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

Successfully merging a pull request may close this issue.

2 participants