microsoft / TypeScript-Vue-Starter

A starter template for TypeScript and Vue with a detailed README describing how to use the two together.
MIT License
4.45k stars 592 forks source link

Typing on props #18

Open blocka opened 7 years ago

blocka commented 7 years ago

It's great that my props are recognized, but the props are all type "any", which doesn't help me much. I see that extend is generic, and the last property is for props. But I can't make heads or tails of what to do with that.

DanielRosenwasser commented 7 years ago

With Vue 2.5, TypeScript can understand basic prop types like

props: {
  foo: String,
  bar: Number,
  baz: Boolean,
}
mmakrzem commented 7 years ago

So there is no way to specify a prop as being of a custom type? ie:

interface IData {
  id: Number;
  name: String;
}

props: {
  foo: IData
}
DanielRosenwasser commented 7 years ago

You could try

props: {
  foo: { default: {} as IData }
}