Vue-next: Declaring props by type does not work

Created on 4 May 2020  路  5Comments  路  Source: vuejs/vue-next

Version

3.0.0-beta.7

Reproduction link

Steps to reproduce

Test.vue

<template>
  <span>{{ label }}</span>
</template>
<script lang="ts">

interface TestProps {
  label: string;
}

export default {
  setup(props: TestProps) {
    return { label: props.label };
  },
};
</script>

The rendering result of <Test label="hello" /> is empty

What is expected?

Show the string "hello"

What is actually happening?

The rendering result is empty


This code worked fine a month ago, and no longer work after I update vue.

In addition, I noticed that the test cases related to this feature are commented out. Can you explain the planning of this part?
@yyx990803

Most helpful comment

@leopiccionia @yyx990803 For TS developers, props must be declared in two places?

interface MyProps {
  label: string;
}

export default {
  props: {
    label: String
  },
  setup(props: MyProps) {
    // ...
  },
};

This is very bad for me, hope to have a better solution.

All 5 comments

The Optional Props Declaration RFC was revoked, and replaced by this active RFC.

@leopiccionia @yyx990803 For TS developers, props must be declared in two places?

interface MyProps {
  label: string;
}

export default {
  props: {
    label: String
  },
  setup(props: MyProps) {
    // ...
  },
};

This is very bad for me, hope to have a better solution.

just setup(props), type of props will be inferred

It's strange that stateful components and functional components declare props in different ways, Hope to have a better way like #1155.

Not seeing the solution here. Should props must be declared in two places when using TS ? 馃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HakamFostok picture HakamFostok  路  3Comments

cexbrayat picture cexbrayat  路  3Comments

NMFES picture NMFES  路  3Comments

pearofducks picture pearofducks  路  3Comments

skirtles-code picture skirtles-code  路  3Comments