@uni-helper/uni-cloud-types
TypeScript icon, indicating that this package has built-in type declarations

0.5.2 • Public • Published

@uni-helper/uni-cloud-types

License

npm

基于 这个 PRVue Language Features (Volar) 已经支持。

安装之后,建议启用 接管模式 Takeover Mode。如果不想启用接管模式,可以安装 TypeScript Vue Plugin (Volar)。启用或安装后需要重启 VSCode。

维护直到官方类型推出。

类型和文档的冲突之处,请以文档为准。

类型源代码在 uni-helper/uni-cloud-types。欢迎提交 ISSUE 和 PR 改进类型。

使用

  • 安装依赖
npm i -D @uni-helper/uni-cloud-types
  • 配置 tsconfig.json,确保 compilerOptions.types 中含有 @dcloudio/types@uni-helper/uni-cloud-typesinclude 包含了对应的 vue 文件

    1.6.0 <= Vue Language Features (Volar) & vue-tsc
    {
      "compilerOptions": {
        "types": ["@dcloudio/types", "@uni-helper/uni-app-types"]
      },
      "include": ["src/**/*.vue"]
    }
    1.0.10 <= Vue Language Features (Volar) & vue-tsc < 1.6.0
    {
      "compilerOptions": {
        "types": ["@dcloudio/types", "@uni-helper/uni-app-types"]
      },
      "vueCompilerOptions": {
        "nativeTags": ["block", "component", "template", "slot"]
      },
      "include": ["src/**/*.vue"]
    }
    0.34.16 <= Vue Language Features (Volar) & vue-tsc < 1.0.10
    {
      "compilerOptions": {
        "types": ["@dcloudio/types", "@uni-helper/uni-app-types"]
      },
      "vueCompilerOptions": {
        "experimentalRuntimeMode": "runtime-uni-app"
      },
      "include": ["src/**/*.vue"]
    }
  • 重启编辑器 / IDE

标注类型

推荐使用 @uni-helper/uni-cloud-types 导出的类型为变量标注类型。

<script setup lang="ts">
import { ref } from 'vue';
import type { UnicloudDbSpaceInfoProvider, UnicloudDbOnLoad } from '@uni-helper/uni-cloud-types';

const spaceInfoProvider = ref<UnicloudDbSpaceInfoProvider>('aliyun');
const onLoad: UnicloudDbOnLoad = (event) => {
  ...
};
</script>

<template>
  <unicloud-db @load="onLoad"></unicloud-db>
</template>

也可以直接使用命名空间来为变量标注类型。

<script setup lang="ts">
import { ref } from 'vue';

const spaceInfoProvider = ref<UniHelper.UnicloudDbSpaceInfoProvider>(50);
const onLoad: UniHelper.UnicloudDbOnLoad = (event) => {
  ...
};
</script>

<template>
  <unicloud-db @load="onLoad"></unicloud-db>
</template>

请查看 src 了解所有类型。

致谢

最初在 uni-base-components-types 得到了灵感。

基于 这个 PR 完成。

Package Sidebar

Install

npm i @uni-helper/uni-cloud-types

Weekly Downloads

368

Version

0.5.2

License

MIT

Unpacked Size

23 kB

Total Files

4

Last publish

Collaborators

  • zguolee
  • modyqyw
  • kejunmao