码迷,mamicode.com
首页 > 其他好文 > 详细

[TypeScript] Represent Non-Primitive Types with TypeScript’s object Type

时间:2017-11-09 22:36:27      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:erro   object c   class   hat   src   ror   sig   rip   分享   

ypeScript 2.2 introduced the object, a type that represents any non-primitive type. It can be used to more accurately type methods such as Object.create. Don‘t confuse it with the Object type or {}, the empty object type, though!

 Type ‘Object‘ gives autocomplete. It includes all the methods which an empty object can have.

技术分享

 But empty object without Object type has not.

技术分享

 

If we try to assign a value to empty object, we get error:

技术分享

In order to do it, we can do:

const object: { [key: string]: any } = {};
object.foo = bar;

 

[TypeScript] Represent Non-Primitive Types with TypeScript’s object Type

标签:erro   object c   class   hat   src   ror   sig   rip   分享   

原文地址:http://www.cnblogs.com/Answer1215/p/7811511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!