I'm currently working on a project that includes a Node JS module located at foo/bar.js
. As I'm developing a TypeScript module in src/mymod.ts
that needs to import foo/bar.js
, I'm facing a challenge in creating a declarations file for the foo/bar.js
module. Where should I place this declarations file?
My attempt at placing a declarations file in foo/bar.d.ts
resulted in an error when I tried to
import * as bar from "../foo/bar"
in my TypeScript module:
File '/tmp/my_proj/foo/bar.d.ts' is not a module.
Below is a snippet of my tsconfig.json
file:
{
"compilerOptions": {
"allowJs": true,
"outDir": "./dist/",
"target": "es2017",
"module": "commonjs",
"strictNullChecks": true
},
"include": [
"./src/"
]
}
Here's a snippet from my declaration file:
// Type definitions for bar
declare module "bar" {
function fun1(n: number) : number;
function fun2(n: number) : number;
function fun3(n: number) : number;
}