最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript, Type Object Is Not Generic - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Jun 22, 2016 at 18:07 khollenbeckkhollenbeck 16.2k18 gold badges68 silver badges102 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论