标签: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