I have already required a global value to my global javascript context:
const fs = require('fs')
Because of some special reason, I have to require it in the global scope.
And I want to write a .d.ts file to declare the global variable with a strong type.
But how to? 'fs' is a module, not a type.
If I give the type like: (in my types.d.ts file)
import * as fsi from 'fs';
declare const fs: fsi;
There will be an error TS2709: Cannot use namespace 'fsi' as a type.
How to declare a global variable of a module in Typescript?
声明为class
对象而不是type
private fsi= new fsi()
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.