<template>
<view class="">{{ title }}</view>
<view class="">{{ obj.name }}</view>
</template>
<script setup lang="ts">
const title = ref('小红') // 类型 string
const obj = reactive({
name: '小明' // 类型 string
})
// 三秒后将值修改成 number
setTimeout(() => {
title.value = 111
obj.name = 999
console.log(obj.aa)
}, 3000)
</script>
![白小纯s](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/001/31/64/15_avatar_mid.jpg?v=1697074485)
- 发布:2023-03-31 11:54
- 更新:2023-03-31 11:54
- 阅读:209
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: macOS 13.2.1 (22D68)
HBuilderX类型: 正式
HBuilderX版本号: 3.7.9
第三方开发者工具版本号: 微信开发者工具 (1.06.2303220darwin-arm64)
基础库版本号: 2.30.3
项目创建方式: HBuilderX
示例代码:
操作步骤:
类型定义
<script setup lang="ts">
const title = ref('小红') // 类型 string
const obj = reactive({
name: '小明' // 类型 string
})
// 三秒后将值修改成 number
setTimeout(() => {
title.value = 111
obj.name = 999
console.log(obj.aa)
}, 3000)
类型定义
<script setup lang="ts">
const title = ref('小红') // 类型 string
const obj = reactive({
name: '小明' // 类型 string
})
// 三秒后将值修改成 number
setTimeout(() => {
title.value = 111
obj.name = 999
console.log(obj.aa)
}, 3000)
预期结果:
编译报错
编译报错
实际结果:
编译未提示错误 通过了编译
编译未提示错误 通过了编译
bug描述:
Vue3 + vite + ts 数据初始类型定义后,修改为任意类型非初始类型编译仍然可以通过
![](http://img-cdn-tc.dcloud.net.cn/uploads/questions/20230331/c9f97d3049b667ead8cc808d8463e6e5.png)