I want to have intellisense for opencv.js inside VS Code when I call it from a JavaScript file, but when I use import "path/opencv.js" or import cv from "path/opencv.js", I can't have intellisense for cv.
In the OpenCV documentation, there are following description and a example:
Once opencv.js is ready, you can access OpenCV objects and functions through cv object. The promise-typed cv object should be unwrap with await operator. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await .
imgElement.onload = await function() {
cv = (cv instanceof Promise) ? await cv : cv;
let mat = cv.imread(imgElement);`
}
but the intellisense doesn't even show a promise-typed cv.
It is worth mentioning that my environment is browser.
Edit:
When I use import cv from "path/opencv.js" VS code detect 'cv' type as:
(alias) (local var) cv: (cv: any, ...args: any[]) => any
The way opencv.js exports its module is very complicated, it is not the modern way of exporting module:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(function () {
return (root.cv = factory());
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals
root.cv = factory();
}
}(this, function () {
var cv = function(cv) {
cv = cv || {};
var Module = cv;
...
import cv from "path/opencv.js"raises error.import pkg from 'path/opencv.js'; const cv = pkg.exportedObjectName;. It works for me when using old amd modules.