15

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?

1 Answer 1

16

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.