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 发布文章使用:只允许注册用户才可以访问!


TypeScript constructor public cause duplicate bug的更多相关文章

  1. Typescript & classes & public shorthand

    classes & public shorthand Also of note, the use of public on arguments to the constructor is a ...

  2. [TypeScript] Export public types from your library

    If you're a library author, it's useful to expose your public types as interfaces, to allow your con ...

  3. Three.js typescript definitely typed 文件

    最近学习three.js,想用typescript编写代码,去http://definitelytyped.org/找了一圈没有发现three.js的definitely typed文件. 好吧,花了 ...

  4. TypeScript: type alias 与 interface

    官方文档中有关于两者对比的信息,隐藏在 TypeScript Handbook 中,见 Interfaces vs. Type Aliases 部分. 但因为这一部分很久没更新了,所以其中描述的内容不 ...

  5. 如何编写 Typescript 声明文件

    使用TypeScript已经有了一段时间,这的确是一个好东西,虽说在使用的过程中也发现了一些bug,不过都是些小问题,所以整体体验还是很不错的. TypeScript之所以叫Type,和它的强类型是分 ...

  6. BetterScroll源码阅读顺便学习TypeScript

    开头 TypeScript已经出来很多年了,现在用的人也越来越多,毋庸置疑,它会越来越流行,但是我还没有用过,因为首先是项目上不用,其次是我对强类型并不敏感,所以纯粹的光看文档看不了几分钟就心不在焉, ...

  7. CSS3与页面布局学习总结(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)

    CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...

  8. TypeScript 素描 - 类

    本文虽然是学自官方教程而来,但是也融入了自己的理解,而且对官方的例子做了一些修改 /* 类 面向对象编程的一大核心 使用C#.Java进行编程的朋友肯定已经是不能够再熟悉了 TypeScript的类与 ...

  9. 转载:《TypeScript 中文入门教程》 7、模块

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 关于术语的一点说明: 请务必注意一点,TypeScript 1.5里术语名已经发生了变 ...

随机推荐

  1. jackson学习之二:jackson-core

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  2. 转 Fiddler3 使用技巧

    Fiddler3 使用技巧  文章转自:https://www.cnblogs.com/zhengna/category/1466001.html 1.Fiddler抓不到包怎么解决 (1)先确定是H ...

  3. Vue基础之插值表达式的另一种用法!附加变量的监听!

    Vue基础之插值表达式的另一种用法!附加变量的监听! 讲这个之前我们先回顾一下原来的用法! <body> <!-- Vue.js的应用可以分为两个重要的组成部分 一个是视图! 另一个 ...

  4. LDAP 简介

    一.使用 Directory Services(目录服务)的目的 对于局域网内的一个用户来讲,工作等其它应用需要,我们必须凭帐号登录主机.用帐号收发E-mail,甚至为了管理需要公司还需要维护一个电子 ...

  5. 墓碑机制与 iOS 应用程序的生命周期

    ① 应用程序的状态 iOS 应用程序一共有 5 种状态: Not running:应用未运行 Inactive:应用运行在 foreground 但没有接收事件 Active:应用运行在 foregr ...

  6. (Oracle)取当前日期的最近工作日

      描述:现有一需求,日期表中存放了日期和是否节假日(0-工作日,1-节假日),现在需要取日期表中的最近的工作日.如2017/07/23(周日)最近的工作日应该是2017/07/21(周五).     ...

  7. linux shell 判断空字符串的几种方法!

    在书写linux shell 脚本我们经常会遇到,对一个字符串是否为空进行判断,下面我对几种常用的方法进行了一个总结: 1.-z判断 -z string True if the length of s ...

  8. 网际互连__TCP/IP三次握手和四次挥手

    在TCP/IP协议中,TCP协议提供可靠的连接服务. 位码即tcp标志位,有6种标示: SYN(synchronous建立联机).ACK(acknowledgement 确认).PSH(push传送) ...

  9. vue、element-ui 依权限动态导航 v-for、v-if

    在管理后台需要按用户权限展示不同导航菜单时,我们需要从后端请求数据来进行菜单渲染. 但由于v-for与v-if不能在同一标签内使用(存在性能问题:v-for 具有比 v-if 更高的优先级,意味着 v ...

  10. 从微信小程序到鸿蒙js开发【04】——list组件

    目录: 1.可滚动区域 2.list + list-item 3.list + list-item-group + list-item 1.可滚动区域 在许多场景中,页面会有一块区域是可滚动的,比如这 ...