ts解决依赖引入报错:无法找到模块“xxxxxx”的声明文件的报错问题

简介: ts解决依赖引入报错:无法找到模块“xxxxxx”的声明文件的报错问题

依赖引入报错是因为ts没有识别当前引入的依赖,在vite-env.d.ts中声明该依赖即可解决,语法:declare module "依赖名";

declare module "file-saver";


解决找不到模块“./App.vue”或其相应的类型声明。

declare module "*.vue" {
  import { DefineComponent } from "vue";
  const component: DefineComponent<{}, {}, any>;
  export default component;
}


解决router引入报错的问题

declare module '*./router' {
  import type { DefineComponent } from 'vue-router'
  const component: DefineComponent<{}, {}, any>
  export default component
}

declare module 'vue-router'

一些依赖报错问题的解决

// <reference types="vite/client" />
// 解决引入vue的报错
declare module "*.vue" {
  import { DefineComponent } from "vue";
  const component: DefineComponent<{}, {}, any>;
  export default component;
}
// 解决引入scss报错问题
declare module "*.scss" {
  const scss: Record<string, string>;
  export default scss;
}
// 解决引入模块的报错提示
declare module "vuedraggable/src/vuedraggable";
declare module "@pureadmin/components";
declare module "@pureadmin/theme";
declare module "@pureadmin/theme/dist/browser-utils";
declare module "nprogress";
declare module "file-saver";
declare module "element-plus/dist/locale/zh-cn.mjs"; /*解决element-plus国际化依赖报错*/
/* 
  解决axios报错:类型“{ params: any; "": any; }”的参数不能赋给类型“AxiosRequestConfig<any>
  解决:属性“xxxxx”在类型”{ $: ComponentInternalInstance; $data : {}; $props:Part......报错问题
  */
declare module "axios" {
  export interface AxiosRequestConfig {
    // 添加数据类型
    handlerEnabled?: boolean;
    baseURL: string;
    timeout: number;
  }
}
// 处理TS数据类型问题  类型“AxiosResponse<any, any>”上不存在属性“meta”。
declare module "axios" {
  interface AxiosResponse<T = any> {
    meta: any;
    // 这里追加你的参数
    baseURL?: string;
    timeout?: number;
  }
  export function create(config?: AxiosRequestConfig): AxiosInstance;
}
目录
打赏
0
0
0
0
4
分享
相关文章
VITE+TS项目中别名需要分别设置避免冲突
VITE+TS项目中别名需要分别设置避免冲突
335 1
Webpack 模块解析:打包原理、构造形式、扣代码补参数和全局导出
Webpack 模块解析:打包原理、构造形式、扣代码补参数和全局导出
394 1
若依修改---重新部署项目注意事项,新文件初始化需要修改的地方,打包后的文件很难进行修改,如果想要不断修改项目,注意保存原项目,才可以不断修改,前端:在Vue.config.js文件中修改target
若依修改---重新部署项目注意事项,新文件初始化需要修改的地方,打包后的文件很难进行修改,如果想要不断修改项目,注意保存原项目,才可以不断修改,前端:在Vue.config.js文件中修改target
导入名为'materials'的模块时出现了错误
导入名为'materials'的模块时出现了错误
144 2
hook+ts业务开发思路5-完成列表页面的编写
hook+ts业务开发思路5-完成列表页面的编写
74 0
hook+ts业务开发思路5-完成列表页面的编写
ts重点学习143-描述文件声明
ts重点学习143-描述文件声明
80 0
ts重点学习143-描述文件声明
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
ts重点学习136-声明合并
ts重点学习136-声明合并
149 0
ES6中模块导入遇到的问题及其解决办法
今天遇到了一个小的问题,我们来看一下,情况是这样的:在没遇到过这个坑之前,如果需要引入一个模块,我通常的做法都是在HTML文件中内嵌一个script标签,并通过指定 type="module" 来实现;然而今天我却没有按照往常这样做,而是指定两个js文件,其中一个文件通过 export 暴露出需要的变量和函数,在另一个文件中通过 import 导入,结果就遇到了报错,来给各位看下报错信息:
ES6中模块导入遇到的问题及其解决办法