B
B
BonBon Slick2020-05-25 14:07:30
typescript
BonBon Slick, 2020-05-25 14:07:30

Does it make sense to do @Prop typing?

@Prop({required: true, type: String}) public readonly icon!: string;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-05-25
@BonBonSlick

If the emitDecoratorMetadata ts-flag is set, then vue-property-decorator will automatically set type for a simple primitive type, i.e. specifically here you can not specify manually. However, if the type is complex or a union of simple ones, then this will no longer work, and then it must be done manually. (I have an unfinished ts-transformer plugin lying around to extend this behavior, but I still can’t get my hands on it.)
This is about the interaction of ts and vue.
If the question is "should vue-typing properties be necessary at all", then the answer is generally: up to you.
There are two reasons to do this:
1. Using your component outside of the ts environment.
2. The behavior of a property whose first type is Booleandifferent from the usual one: such a property is set totrueif it is on a component, even if the value is missing:

<component boolean-prop></component>
// если type: Boolean - booleanProp === true
// если type иной или отсутствует - booleanProp === undefined

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question