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里术语名已经发生了变 ...
随机推荐
- kvm虚拟机管理(创建、连接)
创建虚机.远程管理kvm虚机.virsh命令行下管理虚机..kvm通过virsh console 连入虚拟机 一.创建虚机 1)打开虚拟化管理器
- windows和linux修改ipv6和ipv4的优先级
如果一台机器系统配置ipv6地址和ipv4地址共存,访问两种网站都可以 但有个很尴尬的问题,因为操作系统默认是V6优先于V4,所以比如一个地址同时有A和AAAA记录的话,那么系统会自动选择V6协议通信 ...
- jQuery 勾选显示
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Java Optional使用指南
提到NullPointerException(简称NPE)异常,相信每个Java开发人员都不陌生,从接触编程的第1天起,它就和我们如影随形,最近处理的线上bug中,有不少都是对象没判空导致的NullP ...
- JAVAV EMAIL
package a; import java.util.Date;import java.util.Properties;import javax.mail.Authenticator;import ...
- TCMalloc源码学习(四)(小内存块释放)
pagemap_和pagemap_cache_ PageHeap有两个map,pagemap_记录某一内存页对应哪一个span,显然可能多页对应一个span,pagemap_cache_记录某一内存页 ...
- Python骚操作从列表推导和生成器表达式开始
序列 序列是指一组数据,按存放类型分为容器序列与扁平序列,按能否被修改分为不可变序列与可变序列. 容器序列与扁平序列 容器序列存放的是对象的引用,包括list.tuple.collections.de ...
- Prometheus为你的SpringBoot应用保驾护航
前面我们介绍了Prometheus的作用和整体的架构,相信大家对Prometheus有了一定的了解. 具体可以查看这篇文章:https://mp.weixin.qq.com/s/QoAs0-AYy8k ...
- 内网渗透之信息收集-linux
linux 系统信息 grep MemTotal /proc/meminfo #查看系统内存总量 cat /etc/issue #查看系统名称 ...
- java架构《并发线程基础二》
1.关键字 volatile 使用场景: 针对与多线程公用的数据 用volatile关键字修饰 但其不保证原子性(同步).volatile关键字不具备synchronized ...