How to temporally define a Object type more specifically?

I am using Angular 2.

Usually, when I define a type, I create a interface first:

interface Product {
  name: string,
  count: number

then use like

let product: Product;

Now I want to temporally define a Object type. Something like this:

let product: Object<name: string, count: number>;

But this is wrong. How can I do it correctly? Thanks

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

You’re actually pretty close. It’s called Object literal type definition and it looks like this:

var product: { name : string; count: number; }
// Or if you don't like semi-colons, you can comma-delimit them
var product: { name : string, count : number }

// Later you could utilize it like normal

product = { name : 'joe', count : 5 };

Interfaces are just great because they could be reused everywhere