B
B
BonBon Slick2020-05-13 20:29:52
typescript
BonBon Slick, 2020-05-13 20:29:52

What is the @Component component type for?

An example is taken here

What gives if we specify the type of the component?
It works without it, so why then?

Answer the question

In order to leave comments, you need to log in

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

In this particular case, nothing. However, this generic is used to infer types within the object passed to @Component.

@Component({
  methods: {
    getd(){
      alert(this.messages) // Property "mesages" does note exist on type Vue
    }
  }
})
export default class Home extends Vue {
  messages: string
}
@Component<Home>({
  methods: {
    getd(){
      alert(this.messages) // ok
    }
  }
})
export default class Home extends Vue {
  messages: string
}

Alas, due to the peculiarities of the implementation of decorators, it will not work to deduce the type implicitly in such cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question