首页 > 其他 > 详细

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

时间:2017-11-09 21:24:35      阅读:240      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!