In my node.js app, I have a TypeScript file (util.ts) that defines methods:
export function myFunc() { console.log(42); }
And I use it in another typescript file:
const util = require('./util');
util.myFunc();
This works fine, but the type of util
const is any
. How can I make it typed, in a way that when I type util.
, my editor will know how to auto-complete, and when I write:
util.myOtherFunc();
TypeScript compiler will fail and say that util
doesn't have a myOtherFunc
method?
How can I make it typed
Instead of :
const util = require('./util');
Do :
import util = require('./util');
https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.