How could I set a default props in defineComponent
with typescript?
#10808
-
For example: interface Props {
doSomething?: () => void
}
export default defineComponent<Props>((props) => {
props.doSomething()
}, {
props: {
doSomething: {
default: noop
}
}
}) So the component has a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
you should use the |
Beta Was this translation helpful? Give feedback.
-
sorry, i got confused there for a moment. if you are using 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,
},
},
},
); |
Beta Was this translation helpful? Give feedback.
sorry, i got confused there for a moment. if you are using
defineComponent
, then you can write something like this