Reputation: 853
I'd like to add an "interface subtype" to a component, for example:
@Component
export default class Graph extends Vue
{
@Prop ()
public data: Array<Graph.Data> ;
}
with a sub-interface like:
export interface Data
{
time: Date
value: number
}
in order to enforce the caller to provide correctly formatted props:
<graph :data="data" />
here data
being of type Array<Graph.Data>
.
Any idea...?
Upvotes: 1
Views: 283
Reputation: 135762
TypeScript does not support inner interfaces, but you can use namespace
/module
to achieve what you want:
@Component
class Graph extends Vue
{
@Prop()
public data: Array<Graph.Data>;
}
namespace Graph {
export interface Data {
time: Date
value: number
};
}
export default Graph;
// example variable
var someData: Array<Graph.Data> = [];
See TypeScript playground demo.
Upvotes: 2