admin管理员组文章数量:1435859
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 badges1 Answer
Reset to default 16Define 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
本文标签: javascriptTypeScriptType Object Is Not GenericStack Overflow
版权声明:本文标题:javascript - Typescript, Type Object Is Not Generic - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739106787a2136798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论