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 发布文章使用:只允许注册用户才可以访问!
TypeScript constructor public cause duplicate bug的更多相关文章
- Typescript & classes & public shorthand
classes & public shorthand Also of note, the use of public on arguments to the constructor is a ...
- [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 ...
- Three.js typescript definitely typed 文件
最近学习three.js,想用typescript编写代码,去http://definitelytyped.org/找了一圈没有发现three.js的definitely typed文件. 好吧,花了 ...
- TypeScript: type alias 与 interface
官方文档中有关于两者对比的信息,隐藏在 TypeScript Handbook 中,见 Interfaces vs. Type Aliases 部分. 但因为这一部分很久没更新了,所以其中描述的内容不 ...
- 如何编写 Typescript 声明文件
使用TypeScript已经有了一段时间,这的确是一个好东西,虽说在使用的过程中也发现了一些bug,不过都是些小问题,所以整体体验还是很不错的. TypeScript之所以叫Type,和它的强类型是分 ...
- BetterScroll源码阅读顺便学习TypeScript
开头 TypeScript已经出来很多年了,现在用的人也越来越多,毋庸置疑,它会越来越流行,但是我还没有用过,因为首先是项目上不用,其次是我对强类型并不敏感,所以纯粹的光看文档看不了几分钟就心不在焉, ...
- CSS3与页面布局学习总结(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)
CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...
- TypeScript 素描 - 类
本文虽然是学自官方教程而来,但是也融入了自己的理解,而且对官方的例子做了一些修改 /* 类 面向对象编程的一大核心 使用C#.Java进行编程的朋友肯定已经是不能够再熟悉了 TypeScript的类与 ...
- 转载:《TypeScript 中文入门教程》 7、模块
版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 关于术语的一点说明: 请务必注意一点,TypeScript 1.5里术语名已经发生了变 ...
随机推荐
- 转 5 jmeter性能测试小小的实战
5 jmeter性能测试小小的实战 项目描述 被测网址:www.sogou.com指标:相应时间以及错误率场景:线程数 20.Ramp-Up Period(in seconds) 10.循环次数 ...
- SpringBoot配置文件基础部分说明
SpringBoot-yml文件配置说明 友情提示:有一些代码中有乱码,请脑补删除,适合快速入门 #开启spring的Bebug模式,可以查看有哪些自动配置生效 #debug=true #开启热启动, ...
- 基于final shell的linux命令
final shell操作教程: 1.查看API实时日志:cd ../../data/log/api tail -100f anyAPI-server.log2.关闭日志:control+c3.恢复实 ...
- https://www.cnblogs.com/AloneSword/p/3209653.html
proc/sys/net/ipv4/下各项的意义 - 孤剑 - 博客园 https://www.cnblogs.com/AloneSword/p/3209653.html
- Python中单引号,双引号,三引号的区别
Python中的字符串一般用单引号('A'),双引号("A")和三引号('''A''')或者("""A""") 1.单引 ...
- Java——继承,重载,重写三剑客
About-继承 所有Java的类均是由java.lang.Object类继承而来的,所以Object是所有类的祖先类,而除了Object外,所有类必须有一个父类. 继承可以理解为一个对象从另一个对象 ...
- jquery的ajax发送请求后前端不能实时更新
在IE下用Ajax请求某一页面,通常会因为缓存的原因而返回上一次的结果,造成混乱(比如说多次请求却没有响应). 错误代码如下: $.get("fetch.php") .done(f ...
- Python实现量子态采样
什么是量子态矢量? 在前面一篇量子系统模拟的博客中,我们介绍了使用python去模拟一个量子系统演化的过程.当我们尝试理解量子态和量子门操作时,可以通过其矩阵形式的运算来描述量子态演化的过程: \[\ ...
- 用鸿蒙开发AI应用(七)触摸屏控制LED
[小年答谢,新春送礼]免费抽取1000元京东卡+更多新春好礼~查看详情>>> 目录:前言背景知识编译用户程序框架子系统基于AbilityKit开发的Ability总结 前言上一篇,我 ...
- Pytest(5)美化插件进度条pytest-sugar
前言 在我们进行自动化测试的时候,用例往往是成百上千,执行的时间是几十分钟或者是小时级别.有时,我们在调试那么多用例的时候,不知道执行到什么程度了,而pytest-sugar插件能很好解决我们的痛点. ...