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

Unable to type nested fields in a Node.js module. #58406

Closed
akwotom opened this issue May 2, 2024 · 10 comments
Closed

Unable to type nested fields in a Node.js module. #58406

akwotom opened this issue May 2, 2024 · 10 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@akwotom
Copy link

akwotom commented May 2, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.88.1
  • OS Version: Ubuntu 22.04

Steps to Reproduce:

  1. Setup a node.js project
  2. npm install tranzak-node@3.1.3
  3. Write the following code.
import TRANZAK from 'tranzak-node'
const client = new TRANZAK(/* Just leave the credentials empty */)

// Now, we expect auto complete with the nested fields
const sendFxn = client.sms.send; // VS code doesn't think this is a function. It thinks it is 'any'
// However, the function is actually defined in the module.
// If you Ctrl+Click, on 'sms', you would see the definition of the 'send' function.

Within the node module itself (e.g in index.mjs), you would find that the code is correctly completed.

@akwotom akwotom changed the title Unable to type nested fields a Node.js module. Unable to type nested fields in a Node.js module. May 2, 2024
@mjbvz mjbvz transferred this issue from microsoft/vscode May 2, 2024
@mjbvz
Copy link
Contributor

mjbvz commented May 2, 2024

Their typings files are importing js files:

Image

TS team can weigh in but seems like an issue on the package side to me

@mjbvz mjbvz removed their assignment May 2, 2024
@RyanCavanaugh
Copy link
Member

ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label May 2, 2024
@akwotom
Copy link
Author

akwotom commented May 3, 2024

ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3

Thanks for the insight. I didn't even know such a tool existed.

@akwotom
Copy link
Author

akwotom commented May 3, 2024

ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3

Here's a screenshot from ATTW

Screenshot from 2024-05-03 05-53-12

It says CJSOnlyExportsDefault, which according to my intuition means, only commonjs exports have been done by the package.

However, the actual package.json has configuration for modulejs (mjs), and types

Screenshot from 2024-05-03 06-00-00

And in the index.d.ts, it simply imports the main class of the package.

Screenshot from 2024-05-03 06-04-17

At this point, I expect VS code to correctly infer the type. And yes, it does.

The problem is, nested fields are not working.

@akwotom
Copy link
Author

akwotom commented May 3, 2024

ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3

Screenshot from 2024-05-03 06-13-26

Clearly, the error isn't even about types.

@jakebailey
Copy link
Member

jakebailey commented May 6, 2024

The layout of this package is nonsensical; they're importing from index.mjs (the extension is fine and even required here!), but there is no index.d.mts that describes it. I have no idea how this could have been working before.

@akwotom
Copy link
Author

akwotom commented May 7, 2024

The package has index.d.ts, but no index.d.mts.
And, locally, I just tried renaming all .d.ts files to .d.mts, and changing the reference in package.json, but the situation didn't improve.

@jakebailey
Copy link
Member

That really isn't the problem; the problem is that there really are not any type definitions for this class. Renaming things won't help when there's no type info at at all. This is most definitely a problem with the package.

@akwotom
Copy link
Author

akwotom commented May 7, 2024

327650413-7204a1d7-1d63-4789-8dbd-2ae37d4f4db7

VS code has JS-TS interoperability, where you can import a JavaScript class, and it would be typed correctly.
And when you look at the index.d.ts file, you see how TRANZAK is imported from index.mjs
The expected behaviour, is that VS code would perform it's regular type inference.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "External" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

5 participants