Reputation: 4635
I have the following tsconfig.json in a TypeScript npm package that I maintain.
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"lib": ["es2020"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"moduleResolution": "node",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["scripts/", "test/"]
}
I export all functions, classes, and utilities via default export in index.ts
export default {
CoolClass,
CoolClass2,
utils: {
utilFunction,
utilFunction2,
}
}
I am using the npm package in a normal node v14 project without "type": "module"
. I have eslint enabled. I usually get pretty good intellisense for npm packages that I use.
I don't know why but for the compiled TypeScript from that package, I do not get any intellisense.
const { default as package } = require('mypackage');
const myClass = new package.CoolClass()
// if I hover over CoolClass, it shows (property) SpeechResponse: an
myClass. // if I hover over my class, it shows const resp: any
Also, typed object params loose their intellisense which is very annoying.
package.utils.utilFunction({ typedProperty: ... })
// I don't get any autocompletion for possible properties
I am not sure if I need to alter my tsconfig.json or if the export default might be the issue. Any help would be highly appreciated. Thank you very much!
Upvotes: 0
Views: 212
Reputation: 3179
Please verify you have added the following, when publishing your typescript package to npm. If you had missed out any of the mentioned points, then please add and test out the published package for intellisense:
"declaration": true
to your tsconfig.json
. This tells TypeScript to emit an .d.ts definitions file along with your compiled JavaScript.package.json
, like so(assuming your outDir
in tsconfig is a folder named dist
):"main": "dist/index.js",
"types": "dist/index.d.ts",
"prepublish": "tsc"
Upvotes: 2