by IshKebab · 6y ago · 0 comments
const Component = defineComponent({
props: {
name: String,
success: { type: String },
callback: {
type: Function as PropType<() => void>
},
message: {
type: Object as PropType<ComplexMessage>,
required: true,
validator(message: ComplexMessage) {
return !!message.title
}
}
}
})
Contrast this with React where this would be something like this (I think; I've never used React): interface Props {
name: string;
success: string;
callback: () => void;
message: ComplexMessage;
}
export default class Component extends React.Component<Props> {
...
Quite disappointing. Maybe not that surprising given Evan said he only started using Typescript very recently, and many beginner Javascript developers don't realise that they should really be using Typescript (fortunately Evan isn't one of them). I would recommend still avoiding Vue for this reason alone.Instead, there's the compiler-based approach with `<script setup lang="ts">`: https://docs.google.com/presentation/d/1VjBM6ae-fuawK1TltYLX... (runtime props definitions auto-generated from TS interface)
Fair enough on not wanting to break things, but I still feel like it is Vue's second biggest flaw and worth breaking to fix.
https://class-component.vuejs.org/
You get to define your components as classes with their methods and properties, and can declare props and watchers via decorators. Overall a good typescript experience.