Subscribe on changes!

Composition Api props and emit type declaration

avatar
Dec 29th 2020

What problem does this feature solve?

// props type: ???
// emit type: ???
function useVisibile(props, emit) {
  const visibile = computed({
    set(val) {
      emit("update:modelValue", val);
    },
    get() {
      return props.modelValue;
    }
  });

  return {
    visibile
  };
}

What does the proposed API look like?

How to declare props and emit type

Full Code

<script>
import { defineComponent, computed } from "vue";
import ComDialog from "./ComDialog.vue";

// props type: ???
// emit type: ???
function useVisibile(props, emit) {
  const visibile = computed({
    set(val) {
      emit("update:modelValue", val);
    },
    get() {
      return props.modelValue;
    }
  });

  return {
    visibile
  };
}

export default defineComponent({
  name: "HelloWord",
  components: {
    ComDialog
  },
  props: {
    modelValue: Boolean,
    msg: String
  },
  emits: ["update:"],
  setup(props, { emit }) {
    const { visibile } = useVisibile(props, emit);
    // const visibile = computed({
    //   set(val) {
    //     emit("update:modelValue", val);
    //   },
    //   get() {
    //     return props.modelValue;
    //   }
    // });

    return {
      visibile
    };
  }
});
</script>
avatar
Dec 29th 2020

This is effectively a question about how to annotate function arguments, there is nothing special to consider for Vue here. So this is neither a bug nor a feature request. At best, a topic for documentation over at the vuejs/docs-vext repo.

Please use chat.vuejs.org to ask for help.