zoukankan      html  css  js  c++  java
  • [TypeScript] Represent Non-Primitive Types with TypeScript’s object Type

    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!

    So one thing we need to understand that the Primitive types includes: 'number, boolean, string, symbol, null, undefined'. The 'array, {}, fn()' belongs to 'object' type. The 'object' type therefore is different from 'Object' type in typescript. 'Object' type is referring empty object ( {} ).

     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';
  • 相关阅读:
    java反射
    sql语句
    menu
    亮度
    自定义View
    将多层级xml解析为Map
    Theme.AppCompat无全屏主题解决办法
    Android EditText 限制输入为ip类型
    请不要乱用Kotlin ? 空检查
    配置 jvisualvm 监控Java虚拟机
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7811511.html
Copyright © 2011-2022 走看看