I am pulling in a Javascript file at the top of the React file (I am using Typescript by the way):
let FloDialog = require('../public/js/flo-dialog.min');
Then there is a property for this dialog class:
dialog: FloDialog = null;
Notice that the type should be FloDialog. That is the name of the prototype object contained in the module.
Then in the constructor I initialize the dialog like so:
constructor() {
super();
this.dialog = new FloDialog({
effect: {
fade: true
},
position: 'fixed'
});
}
And later on I call a function on this dialog prototype object to open a dialog. This code does work, but I am getting a Typescript error : TS2304: Cannot find name 'FloDialog'. On the dialog: FloDialog = null;
line.
The module file looks like this:
var FloDialog=function(t){this.id=Date.now(),this.cloak=this.renderCloakHtml()...etc..etc... (minified code)
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = FloDialog;
}
So I export the prototype object as a module. I include it with a require() function. Why isn't the type recognized on line dialog: FloDialog = null;
and how to fix it?
The type FloDialog
is not defined. You don't have a ../public/js/flo-dialog.min.d.ts
to describe what should it look like.
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.