Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue3 typescript 在*.vue中使用reactive指定类型时报错 #7358

Closed
tinnkm opened this issue Aug 17, 2020 · 1 comment
Closed

vue3 typescript 在*.vue中使用reactive指定类型时报错 #7358

tinnkm opened this issue Aug 17, 2020 · 1 comment
Labels
duplicate This issue or pull request already exists F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@tinnkm
Copy link

tinnkm commented Aug 17, 2020

相关平台

微信小程序

小程序基础库: 2.12.1
使用框架: Vue 3

复现步骤

代码片断如下,分别列举三种情况

<script lang="ts">
import { defineComponent, onMounted, reactive } from "vue";
import { QustionDomain } from "../domain/QustionDomain";

export default defineComponent({
  setup() {
    const question:QustionDomain = reactive({ 
      id: "", 
      title: "某用户是?",
      });
    return {
      question
    };
  },
});
</script>

这中情况下编译直接报错,在question: QuestionDomain处提示Unexpected token

<script lang="ts">
import { defineComponent, onMounted, reactive } from "vue";
import { QustionDomain } from "../domain/QustionDomain";

export default defineComponent({
  setup() {
    /**
     * 当前题
     */
    const question = reactive({ 
      id: "", 
      title: "某用户是?"
      }) as QustionDomain;
    return {
      question
    };
  },
});
</script>

这种情况下在as 处提示Unexpected token

<script lang="ts">
import { defineComponent, onMounted, reactive } from "vue";
import { QustionDomain } from "../domain/QustionDomain";

export default defineComponent({
  setup() {
    /**
     * 当前题
     */
    const question = reactive<QustionDomain>({ 
      id: "", 
      title: "某用户是?"
      });
    return {
      question
    };
  },
});
</script>

这种情况下编译不报错,但是页面答应{{question.title}}无内容

期望结果

可以支持类型限制

实际结果

不支持类型限制

环境信息

Taro CLI 3.0.7 environment info:
    System:
      OS: Windows 8.1
    Binaries:
      Node: 14.7.0 - E:\Program Files\nodejs\node.EXE
      npm: 6.14.7 - E:\Program Files\nodejs\npm.CMD

补充信息

只有在不做任何类型限制的时候,页面才可以做正确的显示

@taro-bot2 taro-bot2 bot added F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Aug 17, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 17, 2020

duplicated #7335

@Chen-jj Chen-jj closed this as completed Aug 17, 2020
@Chen-jj Chen-jj added the duplicate This issue or pull request already exists label Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants