TypeScript
TypeScript copied to clipboard
Unable to type nested fields in a Node.js module.
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.88.1
- OS Version: Ubuntu 22.04
Steps to Reproduce:
- Setup a node.js project
npm install tranzak-node- 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.
Their typings files are importing js files:
TS team can weigh in but seems like an issue on the package side to me
ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3
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.
ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3
Here's a screenshot from ATTW
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
And in the index.d.ts, it simply imports the main class of the package.
At this point, I expect VS code to correctly infer the type. And yes, it does.
The problem is, nested fields are not working.
ATTW says this is misconfigured: https://arethetypeswrong.github.io/?p=tranzak-node%403.1.3
Clearly, the error isn't even about types.
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.
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.
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.
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.
This issue has been marked as "External" and has seen no recent activity. It has been automatically closed for house-keeping purposes.