zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    TS type different String / string

    String / string

    
    
    

    https://stackoverflow.com/questions/14727044/typescript-difference-between-string-and-string

    Object vs object

    
    class SVGStorageUtils {
      // Object
      store: Object;
      // object
      constructor(store: object) {
        this.store = store;
      }
      // string primitive
      setData(key: string = ``, data: object) {
        sessionStorage.setItem(key, JSON.stringify(data));
      }
      // String Object
      getData(key: String = ``) {
        const obj = JSON.parse(sessionStorage.getItem(key));
      }
      clear(key: any) {
        delete this.store[key];
      }
      clearAll() {
        this.store = {};
      }
      init() {
        this.store = {};
      }
    }
    
    
    
    
    

    TypeScript: String vs string

    Argument of type 'String' is not assignable to parameter of type 'string'.

    'string' is a primitive, but 'String' is a wrapper object.

    Prefer using 'string' when possible.

    demo

    String Object

    // error
    class SVGStorageUtils {
      store: object;
      constructor(store: object) {
        this.store = store;
      }
      setData(key: String = ``, data: object) {
        sessionStorage.setItem(key, JSON.stringify(data));
      }
      getData(key: String = ``) {
        const obj = JSON.parse(sessionStorage.getItem(key));
      }
    }
    
    

    string primitive

    // ok
    class SVGStorageUtils {
      store: object;
      constructor(store: object) {
        this.store = store;
      }
      setData(key: string = ``, data: object) {
        sessionStorage.setItem(key, JSON.stringify(data));
      }
      getData(key: string = ``) {
        const obj = JSON.parse(sessionStorage.getItem(key));
      }
    }
    
    

    enter image description here



    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    嵌入式系统引导和启动的流程
    microblaze以太网程序
    机试题
    共模差分 对比
    xilinx XPS无法启动的问题
    FPGA开发流程
    Mel-Frequency-Warping
    微软-黄学东-清华大学FIT楼报告-20170407
    Matlab
    Anaconda安装
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/12311276.html
Copyright © 2011-2022 走看看