Skip to content

How could I set a default props in defineComponent with typescript? #10808

Discussion options

You must be logged in to vote

sorry, i got confused there for a moment. if you are using defineComponent, then you can write something like this

import { defineComponent, h, type PropType } from "vue";

interface Props {
  doSomething?: () => void;
}

const noop = () => {};

export default defineComponent<Props>(
  (props) => {
    props.doSomething();
    return () => {
      // render function or JSX
      return h('div', 'Hello world!');
    }
  },
  {
    props: {
      doSomething: {
        type: Function as PropType<Props["doSomething"]>,
        default: noop,
      },
    },
  },
);

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@s3xysteak
Comment options

Comment options

You must be logged in to vote
1 reply
@s3xysteak
Comment options

Answer selected by s3xysteak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants