uni-helper / uni-typed

为 uni-app、uni-cloud 和 uni-ui 组件提供 TypeScript 类型支持
MIT License
37 stars 3 forks source link

Visual Studio Code 中uni-app内置组件报错。 #9

Closed gunsluo closed 3 months ago

gunsluo commented 3 months ago

描述问题

项目使用Vues + ts 构建, 能正常开发和编译。但在Visual Studio Code中显示错误:

image

uni-ui组件无报错信息,uni-app内置组件view, text, button. 有错误提示:

Argument of type '{ class: string; }' is not assignable to parameter of type 'ComponentPublicInstanceConstructor<CreateComponentPublicInstance<Readonly<ExtractPropTypes<Partial<{ selectable: boolean; userSelect: boolean; space: _TextSpace; decode: boolean; }>>>, {}, ... 17 more ..., {}>, ... 4 more ..., MethodOptions> & ... 4 more ... & Record<...>'.
  Type '{ class: string; }' is not assignable to type 'ComponentPublicInstanceConstructor<CreateComponentPublicInstance<Readonly<ExtractPropTypes<Partial<{ selectable: boolean; userSelect: boolean; space: _TextSpace; decode: boolean; }>>>, {}, ... 17 more ..., {}>, ... 4 more ..., MethodOptions>'.
    Type '{ class: string; }' provides no match for the signature 'new (...args: any[]): CreateComponentPublicInstance<Readonly<ExtractPropTypes<Partial<{ selectable: boolean; userSelect: boolean; space: _TextSpace; decode: boolean; }>>>, ... 18 more ..., {}>'.ts-plugin(2345)

package.json

{
  "name": "ui",
  "version": "0.1.0",
  "scripts": {
    "dev:app": "uni -p app",
    "dev:app-android": "uni -p app-android",
    "dev:app-ios": "uni -p app-ios",
    "dev:custom": "uni -p",
    "dev:h5": "uni",
    "dev:h5:ssr": "uni --ssr",
    "dev:mp-alipay": "uni -p mp-alipay",
    "dev:mp-baidu": "uni -p mp-baidu",
    "dev:mp-jd": "uni -p mp-jd",
    "dev:mp-kuaishou": "uni -p mp-kuaishou",
    "dev:mp-lark": "uni -p mp-lark",
    "dev:mp-qq": "uni -p mp-qq",
    "dev:mp-toutiao": "uni -p mp-toutiao",
    "dev:mp-weixin": "uni -p mp-weixin",
    "dev:mp-xhs": "uni -p mp-xhs",
    "dev:quickapp-webview": "uni -p quickapp-webview",
    "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
    "dev:quickapp-webview-union": "uni -p quickapp-webview-union",
    "build:app": "uni build -p app",
    "build:app-android": "uni build -p app-android",
    "build:app-ios": "uni build -p app-ios",
    "build:custom": "uni build -p",
    "build:h5": "uni build",
    "build:h5:ssr": "uni build --ssr",
    "build:mp-alipay": "uni build -p mp-alipay",
    "build:mp-baidu": "uni build -p mp-baidu",
    "build:mp-jd": "uni build -p mp-jd",
    "build:mp-kuaishou": "uni build -p mp-kuaishou",
    "build:mp-lark": "uni build -p mp-lark",
    "build:mp-qq": "uni build -p mp-qq",
    "build:mp-toutiao": "uni build -p mp-toutiao",
    "build:mp-weixin": "uni build -p mp-weixin",
    "build:mp-xhs": "uni build -p mp-xhs",
    "build:quickapp-webview": "uni build -p quickapp-webview",
    "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
    "build:quickapp-webview-union": "uni build -p quickapp-webview-union",
    "type-check": "vue-tsc --noEmit"
  },
  "dependencies": {
    "@dcloudio/uni-app": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-app-plus": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-components": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-h5": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-alipay": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-baidu": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-jd": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-lark": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-qq": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-weixin": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-mp-xhs": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-ui": "^1.5.6",
    "vue": "^3.4.35"
  },
  "devDependencies": {
    "@dcloudio/types": "^3.4.12",
    "@dcloudio/uni-automator": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-cli-shared": "3.0.0-alpha-4020520240731001",
    "@dcloudio/uni-stacktracey": "3.0.0-alpha-4020520240731001",
    "@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020520240731001",
    "@types/wechat-miniprogram": "^3.4.7",
    "@uni-helper/uni-types": "1.0.0-alpha.1",
    "@vue/runtime-core": "^3.4.35",
    "@vue/tsconfig": "^0.5.1",
    "sass": "^1.77.8",
    "typescript": "^5.5.4",
    "vite": "^5.3.5",
    "vue-tsc": "^2.0.29"
  },
  "packageManager": "pnpm@9.6.0+sha256.dae0f7e822c56b20979bb5965e3b73b8bdabb6b8b8ef121da6d857508599ca35"
}

tsconfig.json

{
  "compilerOptions": {
    "lib": [
      "DOM",
      "DOM.Iterable",
      "ESNext"
    ],
    "module": "ESNext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "jsx": "preserve",
    "jsxImportSource": "vue",
    "noImplicitThis": true,
    "strict": true,
    "verbatimModuleSyntax": true,
    "target": "ESNext",
    "useDefineForClassFields": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    },
    "types": [
      "vite/client",
      "@dcloudio/types",
      "@types/wechat-miniprogram",
      "@uni-helper/uni-types"
    ]
  },
  "vueCompilerOptions": {
    "plugins": [
      "@uni-helper/uni-types/volar-plugin"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "*.d.ts"
  ]
}

复现

visual studio code 的插件

  1. pnpm i 安装依赖
  2. 用 visual studio code 打开项目

uni-app内置组件在visual studio code 中显示错误。

系统信息


基础环境信息:

基础依赖信息:

uni-helper依赖信息:

uni-helper插件信息:


使用的包管理器

pnpm

核对

mxp131011 commented 3 months ago

vue3.3+可以使用 https://gitee.com/mxp_open/mxp-uni-types 代替,注意pinia不要升级到 2.2.0就行,可不用配置

"vueCompilerOptions": {
    "plugins": [
      "mxp-uni-types/volar-plugin"
    ]
  },