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. Centos 7 Redis 安装并开机启动

    一.下载并编译 cd /usr/local/bin目录可以自己选,我将redis安装到/usr/local/bin目录下.wget http://download.redis.io/releases/ ...

  2. 用tqdm和rich为固定路径和目标的python算法代码实现进度条

    适用场景 在存在固定长度的算法中可以可视化算法执行的过程,比如对一个固定长度的数组的遍历,就是一种适合使用进度条来进行可视化的场景.而一些条件循环,比如while循环,不一定适合使用进度条来对算法执行 ...

  3. 济南学习D1T1_haha

    [问题描述] 栈是一种强大的数据结构,它的一种特殊功能是对数组进行排序.例如,借助一个栈,依次将数组1,3,2按顺序入栈或出栈,可对其从大到小排序: 1入栈:3入栈:3出栈:2入栈:2出栈:1出栈. ...

  4. HarmonyOS三方件开发指南(7)——compress组件

    目录:1. 组件compress功能介绍2. 组件compress使用方法3. 组件compress开发实现 1. 组件compress功能介绍1.1.  组件介绍:        compress是 ...

  5. 基础知识——TCP协议

    七层网络模型:物理层,数据链路层,网络层,传输层,会话层,表示层,应用层. 五层网络模型: 1. 应用层:确定进程之间通信的性质以满足用户需求.(各种传输协议) 2. 运输层:负责主机间不同进程的通信 ...

  6. go语言常见面试题

    前言 从网上找了一些面试题,觉得有意思的我都记录下来,自己学习和大家一起学习吧. 有些初级的题目只放答案,一些值得探讨的问题我会写上我自己的分析过程,希望大家多多交流. 原文链接 选择题 1.[初级] ...

  7. 浅谈Webpack模块打包工具一

    为什么要使用模块打包工具 1.模块化开发ES Modules存在兼容性问题 打包之后成产阶段编译为ES5 解决兼容性问题 2.模块文件过多 网络请求频繁  开发阶段把散的模块打包成一个模块 解决网络请 ...

  8. leetcode常见问题

    开学了 开始每日刷leetcode了  ,开一个新分类记录做题过程和心得. 1.出现本地调试无问题但提交后报错时,很有可能是全局变量导致的,解决办法 (1).尽量写成局部变量,函数尽量传参进入. (2 ...

  9. Codeforces Round #673 (Div. 2) D. Make Them Equal(数论/构造)

    题目链接:https://codeforces.com/contest/1417/problem/D 题意 给出一个大小为 $n$ 的正整数数组 $a$ ,每次操作如下: 选择 $i,j$ 和 $x$ ...

  10. 【poj 2752】Seek the Name, Seek the Fame(字符串--KMP)

    题意:给出一个字符串str,求出str中存在多少子串,使得这些子串既是str的前缀,又是str的后缀.从小到大依次输出这些子串的长度. 解法:利用KMP中next[ ]数组的性质,依次找到前缀.后缀匹 ...