0.5.13 • Published 22 days ago
@uni-helper/uni-app-types v0.5.13
@uni-helper/uni-app-types
- @uni-helper/uni-app-types (当前仓库)提供
uni-app
组件类型 - @uni-helper/uni-cloud-types 提供
uni-cloud
组件类型 - @uni-helper/uni-ui-types 提供
uni-ui
组件类型
基于 这个 PR,Vue - Official(即 Volar) 已经支持。
安装之后,请参考 这里 配置你的 VS Code。启用或安装后需要重启 VS Code。
维护直到官方类型推出。
类型和文档的冲突之处,请以文档为准。
类型源代码在 uni-helper/uni-app-types。欢迎提交 ISSUE 和 PR 改进类型。
使用
配置
安装依赖
npm i -D @uni-helper/uni-app-types
配置
tsconfig.json
,确保compilerOptions.types
中含有@dcloudio/types
和@uni-helper/uni-app-types
且include
包含了对应的vue
文件{ "compilerOptions": { "types": ["@dcloudio/types", "@uni-helper/uni-app-types"] }, "vueCompilerOptions": { "plugins": ["@uni-helper/uni-app-types/volar-plugin"] }, "include": ["src/**/*.vue"] }
{ "compilerOptions": { "types": ["@dcloudio/types", "@uni-helper/uni-app-types"] }, "vueCompilerOptions": { "nativeTags": ["block", "component", "template", "slot"] }, "include": ["src/**/*.vue"] }
{ "compilerOptions": { "types": ["@dcloudio/types", "@uni-helper/uni-app-types"] }, "include": ["src/**/*.vue"] }
{ "compilerOptions": { "types": ["@dcloudio/types", "@uni-helper/uni-app-types"] }, "vueCompilerOptions": { "nativeTags": ["block", "component", "template", "slot"] }, "include": ["src/**/*.vue"] }
{ "compilerOptions": { "types": ["@dcloudio/types", "@uni-helper/uni-app-types"] }, "vueCompilerOptions": { "experimentalRuntimeMode": "runtime-uni-app" }, "include": ["src/**/*.vue"] }
- 重启编辑器 / IDE
标注类型
推荐使用 @uni-helper/uni-app-types
导出的类型为变量标注类型。
<script setup lang="ts">
import { ref } from 'vue';
import type { ScrollViewOnScroll } from '@uni-helper/uni-app-types';
const onScroll: ScrollViewOnScroll = (event) => {
...
};
</script>
<template>
<scroll-view @scroll="onScroll"></scroll-view>
</template>
也可以直接使用命名空间来为变量标注类型。
<script setup lang="ts">
import { ref } from 'vue';
const onScroll: UniHelper.ScrollViewOnScroll = (event) => {
...
};
</script>
<template>
<scroll-view @scroll="onScroll"></scroll-view>
</template>
如果你需要传入事件之外的参数,可以参考以下例子。参数顺序参考了 Vue 文档的示例(见 在内联事件处理器中访问事件参数)。
<script setup lang="ts">
import { ref } from 'vue';
import type { ScrollViewOnScrollEvent } from '@uni-helper/uni-app-types';
const onScroll = (text: string, event: ScrollViewOnScrollEvent) => {
...
};
</script>
<template>
<scroll-view @scroll="onScroll('ScrollViewA', $event)"></scroll-view>
<scroll-view @scroll="onScroll('ScrollViewB', $event)"></scroll-view>
</template>
请查看 src 了解所有类型。
致谢
最初在 uni-base-components-types 得到了灵感。
基于 这个 PR 完成。
0.5.13
22 days ago
0.5.10
8 months ago
0.5.11
8 months ago
0.5.9
9 months ago
0.5.12
8 months ago
0.5.8
1 year ago
0.5.8-0
1 year ago
0.5.7
1 year ago
0.5.4
1 year ago
0.5.6
1 year ago
0.5.5
1 year ago
0.5.3
1 year ago
0.5.2
1 year ago
0.5.0
1 year ago
0.5.1
1 year ago
0.3.2
1 year ago
0.4.0
1 year ago
0.3.1
1 year ago
0.3.0
1 year ago
0.3.0-3
1 year ago
0.2.0
1 year ago
0.3.0-1
1 year ago
0.3.0-0
1 year ago
0.3.0-2
1 year ago
0.1.8
2 years ago
0.1.7
2 years ago