On the problem of using typescript to refer to public js in vue-cli projects

the vue project I built through vue-cli3 selected the module that supports ts, and then wrote a public js file today. The error report is not declared when it is introduced with import in main.js, but it can be used. The error message is as follows:

21:23 Could not find a declaration file for module "./libs/commonFun.js". "E:///internal-recommended/src/libs/commonFun.js" implicitly has an "any" type.
    19 | Vue.config.devtools = true;
    20 | // js
  > 21 | import commonFun from "./libs/commonFun.js";
       |                       ^
    22 | Vue.prototype.commonFun = commonFun;
    23 |
    24 | new Vue({
Version: typescript 3.1.6

main.js introduction code is as follows

// js
import commonFun from "./libs/commonFun.js";
Vue.prototype.commonFun = commonFun;

commonFun.js is as follows

import {
    MessageBox
} from "element-ui";
export default {
    showConfirm(option) {
        MessageBox.confirm(option.confirmtxt, "", {
            confirmButtonText: option.confirmoktxt,
            cancelButtonText: option.confirmcanceltxt,
            type: "warning",
            center: true
        }).then(() => {
            option.success()
        }).catch(() => {
            console.log("")
        });
    }
}

because I used ts for the first time, I did not find the declaration of this kind of introduction file in the official document, and Baidu did not find the relevant information. I also asked the boss who thought no to help me to express my thanks.

May.14,2022

tsconfig.json

{
  "compilerOptions": {
    "allowJS": true,
    ...
  },
  ...
}

is the boss problem solved? I have the same problem


look at this, the d.ts file declares

if you look at some npm libraries that support ts, you will find that he will declare such xxx.d.ts files, which need to be declared.


has the landlord solved it?

Menu