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. Vue项目之实现登录功能的表单验证!

    Vue项目之实现登录功能的表单验证! 步骤: 配置 Form表单验证; 1.必须给el-from组件绑定model 为表单数据对象 2 给需要验证的表单项 el-form-item 绑定 prop 属 ...

  2. WinForm中实现按Enter将光标移动到下一个文本框

    首先窗体加载出来是上面这个样子.有五个文本框,我们要实现的功能就是输入姓名后按Enter,使光标直接定位到手机号中. 在页面加载的时候我们就要获取所有文本框控件,并添加回车事件 private voi ...

  3. LVS负载均衡之DR模式原理介绍

    LVS基本原理 流程解释: 当用户向负载均衡调度器(Director Server)发起请求,调度器将请求发往至内核空间 PREROUTING 链首先会接收到用户请求,判断目标 IP 确定是本机 IP ...

  4. MySQL调优之索引优化

    一.索引基本知识 1.索引的优点 1.减少了服务器需要扫描的数据量 2.帮助服务器避免排序和临时表 例子: select * from emp orde by sal desc; 那么执行顺序: 所以 ...

  5. 配置HDFS的HA

    配置前准备: -- 配置hadoop -- 配置ZooKeeper,传送门:https://www.cnblogs.com/zhqin/p/11906106.html 安装配置好hadoop和ZooK ...

  6. __init__ raises an exception, then __del__ will still be called

    issue 808164: socket.close() doesn't play well with __del__ - Python tracker https://bugs.python.org ...

  7. Flash图解线程池 | 阿里巴巴面试官希望问的线程池到底是什么?

    前言 前几天小强去阿里巴巴面试Java岗,止步于二面. 他和我诉苦自己被虐的多惨多惨,特别是深挖线程和线程池的时候,居然被问到不知道如何作答. 对于他的遭遇,结合他过了一面的那个嘚瑟样,我深表同情(加 ...

  8. Mysql 5.5升级5.8

    前言,因为升级跳板机,需要将mariadb 升级到10.2,也就是对应MySQL的5.8,废话不多说下面开始进行mariadb 5.5 的升级 Welcome to the MariaDB monit ...

  9. python模块----yagmail模块、smtplib模块 (电子邮件)

    yagmail模块 python标准库发送电子邮件的模块比较复杂,so,许多开源的库提供了更加易用的接口来发送电子邮件,其中yagmail是使用比较广泛的开源项目,yagmail底层依然使用smtpl ...

  10. (6)dd命令安装Linux

    1.面对大批量服务器的安装,人们往往热衷于选择"无人值守安装"的方式,而此方式需要对服务器进行过多的配置,并不适合初学者. 无人值守安装(Kickstart),又称全自动安装,其工 ...