I am currently working with some javascript modules with no .d.ts
in typescript environment. The problem currently I am approaching is there is no suggestion in typescript file for javascript modules. For example, I have this file:
// ./test1.js
module.exports = {
data1: "hehe",
data2: Math.PI,
func1: function() { return "hello, world!"; }
};
When I try to get some suggestion in javascript file, it works:
But, when I try in typescript file, it not give the suggestion:
The project has been setup using NextJS via pnpm dlx create-next-app@latest
. I don't want to make .d.ts
to satisfy the typescript intellisense, I just want the intellisense to grasp everything like what has been done with javascript suggestion, as This example above is just hypotetical situation.
In my real project, I works with some javascript modules which has no support for typescript. Even it has, I may approach the same thing when I use other javascript module or even some old one which has no active maintainer. So, I want to avoid this worst case, and instead try to config intellisense to understand js module without .d.ts
file. Could this be possible? Is this a bug?
Here are my tsconfig.json
and package.json
// tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
// package.json
{
"name": "nextjs_sample_page",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@types/node": "20.3.1",
"@types/react": "18.2.13",
"@types/react-dom": "18.2.6",
"eslint": "8.43.0",
"eslint-config-next": "13.4.7",
"next": "13.4.7",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.1.3",
"wrtc": "^0.4.7"
}
}
And this is how I setup my environment:
To be short, my only question is how to make Typescript Intellisense works along with javascript library which not have type, and not have active maintainer and contributor, without creating .d.ts
by myself. The library is abandoned enough which create a situation where no contributor creating the .d.ts
for that library.