Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  144] [ 5]  / answers: 1 / hits: 43983  / 8 Years ago, wed, june 22, 2016, 12:00:00

I am trying to create a type for an Object. But can't seem to get it right. This is what I have.



private test:Object<Test>;

this.test = {id : 'test'};

interface Test
{
id : string;
}


This doesn't work. This gives me the following error:




Type Object Is Not Generic




What is the right way (syntax) to create types for Objects like this?


More From » typescript

 Answers
11

Define a class Test:



export class Test {
field1: number;
field2: string;
/// ...
}


then



private test:Test;


Update: Sorry, didn't notice you have Test as interface. It's fine too.



So same usage, you don't need Object<Test>, just Test


[#61683] Sunday, June 19, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryanulyssesb

Total Points: 91
Total Questions: 105
Total Answers: 102

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
ryanulyssesb questions
Sat, Mar 20, 21, 00:00, 3 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
Mon, Mar 9, 20, 00:00, 4 Years ago
Sun, Jul 7, 19, 00:00, 5 Years ago
;