xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

TypeScript constructor public cause duplicate bug

TypeScript constructor public cause duplicate bug

constructor public

const log = console.log;


// constructor public
class TS4x {
  constructor(public version: string, public author: string) {
    this.version = version;
    this.author = author;
    this.init();
  }
  init() {
    log(`init`);
  }
}

var log = console.log;
// constructor public
var TS4x = /** @class */ (function () {
    function TS4x(version, author) {
        this.version = version;
        this.author = author;
        this.version = version;
        this.author = author;
        this.init();
    }
    TS4x.prototype.init = function () {
        log("init");
    };
    return TS4x;
}());

solution ✅

https://github.com/microsoft/TypeScript/issues/41876

const log = console.log;

class TS4x1 {
  constructor(public version: string, public author: string) {
    // auto assignment 🚀
    this.init();
  }
  init() {
    log(`init`);
  }
}

var log = console.log;

// constructor public
var TS4x1 = /** @class */ (function () {
    function TS4x1(version, author) {
        this.version = version;
        this.author = author;
        // auto assignment 🚀
        this.init();
    }
    TS4x1.prototype.init = function () {
        log("init");
    };
    return TS4x1;
}());

demos


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-12-07
 * @modified
 *
 * @description
 * @augments
 * @example
 * @link
 *
 */

const log = console.log;


// constructor public
class TS4x {
  constructor(public version: string, public author: string) {
    this.version = version;
    this.author = author;
    this.init();
  }
  init() {
    log(`init`);
  }
}

// public
class TS4x2 {
  public version: string;
  public author: string;
  constructor(version: string, author: string) {
    this.version = version;
    this.author = author;
    this.init();
  }
  init() {
    log(`init`);
  }
}

// private
class TS4x3 {
  private version: string;
  private author: string;
  constructor(version: string, author: string) {
    this.version = version;
    this.author = author;
    this.init();
  }
  init() {
    log(`init`, this.version);
    log(`init`, this.author);
  }
}

// protected
class TS4x4 {
  protected version: string;
  protected author: string;
  constructor(version: string, author: string) {
    this.version = version;
    this.author = author;
    this.init();
  }
  init() {
    log(`init`, this.version);
    log(`init`, this.author);
  }
}



export default TS4x;

export {
  TS4x,
  TS4x2,
  TS4x3,
  TS4x4,
};




refs



©xgqfrms 2012-2020

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


posted @ 2020-12-08 19:03  xgqfrms  阅读(106)  评论(4)    收藏  举报