Comments (19)
demo地址:https://gitee.com/Megasu/uni-app-types-demo
- 自定义的类型声明文件需要写成
declare module 'vue'
写成@vue/runtime-core
反而无法工作。 - tsconfig.json 有没有 include 这个 components.d.ts?有的,默认模板中自动加载 src 目录下所有的 d.ts 文件。
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
from uni-app-types.
但解决了就好。
from uni-app-types.
全局组件在 src\pages.json
中通过 easycom
配置自动注册,在项目中全局组件可正常工作。
{
"easycom": {
"autoscan": true,
"custom": {
// 自定义全局组件,把 components 文件夹中以 Xtx 开头的 vue 组件,注册为全局组件
"^Xtx(.*)": "@/components/Xtx$1.vue"
}
},
}
from uni-app-types.
我这里复现不出来。方便的话可以给个 demo?
两个点我比较在意。
- uni-app-types 里面全局组件的定义都是基于
@vue/runtime-core
的,而你给出的示例是declare module 'vue'
,不太确定有没有影响。
- tsconfig.json 有没有 include 这个 components.d.ts?
from uni-app-types.
demo地址:https://gitee.com/Megasu/uni-app-types-demo
- 自定义的类型声明文件需要写成
declare module 'vue'
写成@vue/runtime-core
反而无法工作。- tsconfig.json 有没有 include 这个 components.d.ts?有的,默认模板中自动加载 src 目录下所有的 d.ts 文件。
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
请问作者您那边能复现问题吗? @ModyQyW
from uni-app-types.
我这边使用了你提供的 demo。components.d.ts 里面写成 declare module 'vue'
和 declare module '@vue/runtime-core'
都能正常工作,而且不需要三斜线指令。
from uni-app-types.
volar 官方文档建议 vue 3 使用 declare module '@vue/runtime-core'
。
from uni-app-types.
我觉得需要你检查一下 VSCode 本地配置,包括 Volar 和 Take Over Mode,最后需要 Reload Window 试一下。看起来我这边无能为力。
from uni-app-types.
volar 官方文档建议 vue 3 使用 declare module '@vue/runtime-core'。
- 按官方建议修改后反而类型失效
- 已清空所有 VsCode 本地配置
- 已开启 Volar 和 Take Over Mode
- 已 Reload Window ,甚至是重启编辑器。
from uni-app-types.
Vant 组件库也是通过 declare module 'vue' 注册类型的
declare module 'vue' {
export interface GlobalComponents {
VanButton: typeof Button;
}
}
源码地址:https://github.com/youzan/vant/blob/main/packages/vant/src/button/index.ts
from uni-app-types.
我也无法定位到 Bug 的原因,目前我和我同事都只能通过 declare module 'vue'
注册全局组件的类型,用 declare module '@vue/runtime-core'
反而不行。
删除掉了三斜杠的引入方式, uni-app 组件的类型就无法识别,截图中类型为 unknow。
from uni-app-types.
volar 官方文档建议 vue 3 使用
declare module '@vue/runtime-core'
。
其实我也不知道 Volar 作者为什么定义全局组件的类型还要分 Vue 的版本写,为什么不能统一写法,同时按官方要求用 declare module '@vue/runtime-core'
反而无法工作。
from uni-app-types.
我是觉得非常奇怪,为什么同样的代码,您那边可以正常运行,为了排除变化,我已经注释掉了所有设置,还是一样情况。
我这边使用了你提供的 demo。components.d.ts 里面写成
declare module 'vue'
和declare module '@vue/runtime-core'
都能正常工作,而且不需要三斜线指令。
from uni-app-types.
我也正在迷惑这一点……
from uni-app-types.
刚刚通过 pnpm i -D @vue/runtime-core
,需要显性的安装了 @vue/runtime-core
才行。
显式安装后依赖包后就不出现冲突了,可以删除掉三斜杠的引入。
问题虽然解决了,但是还是存在一些迷惑。
from uni-app-types.
这真的挺诡异的。因为 vue 本身 dependencies 里有 @vue/runtime-core,不明白为什么没有安装上。
from uni-app-types.
你用的 pnpm, 这是由于 pnpm 默认的文件结构导致的
要在项目根目录创建 .npmrc
文件, 并添加 shamefully-hoist=true
之后重新运行 pnpm install
, 重启编辑器, 就没问题了
from uni-app-types.
确实是。我之前设了全局的 .npmrc
都忘了
from uni-app-types.
@Zhang-Wei-666 非常感谢。
from uni-app-types.
Related Issues (12)
- Dependency Dashboard
- types declare HOT 2
- 优化类型 HOT 1
- 降低类型使用成本 HOT 12
- @vue/server-renderer依赖版本跟uni官方提供的vue库依赖版本不一致 HOT 5
- 建议增加组件 event 类型 HOT 4
- `CustomEvent` 等事件类型的讨论 HOT 5
- Volar 更新到 1.0.10 后配置失效 HOT 5
- vscode 自动升级volar 插件导致的 uni-app-types 类型失效 HOT 8
- volar / vue-tsc@^1.6.4 该如何配置? HOT 16
- `nativeTags` Usage problem HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uni-app-types.