// let num:number = 12;
// let boo:boolean = true;
// let str:string = "adfd";
// str = 'asdf';
// str = `
// <h1>${num*3+3}</h1>
// `;
// alert(str); // console.info(str.indexOf("h"));
// console.info(parseFloat("123.4343abc"))
// let num2 = 20;
// console.info(num2);
let arr:(number|string)[] = [1,2,3,"dfsdf"];
arr.push(2); let arr2 :Array<number> = [1,2,4];
arr2.push(222);
console.log(arr2); enum StudentType{
班长=101,学委=201,组长,学员
} let stuType:StudentType = 201; if(stuType == StudentType.班长){
console.info("班长来了")
}else if(stuType == StudentType.学委){
console.info("学委来了")
} let fun:Function = ()=>{ }
let obj:Date = new Date(); class Student {
public id:number;
public name:string;
/**
* 初始化学生对象
* @param id 学生编号
* @param name 学生名称
*/
constructor(id:number,name:string){
this.id = id;
this.name = name;
} public show(otherName:string):void{
console.info(`你好${otherName},我叫${this.name}`);
}
}
let stu:Student = new Student(1,"王五"); stu.show("李四") class Teacher {
constructor(protected id:number,protected name:string) {
}
public show(otherName: string): void {
console.info(`你好${otherName},我叫${this.name}`);
}
} let teacher:Teacher = new Teacher(12,"hehe");
teacher.show("bb"); class ManTeacher extends Teacher{
constructor(){
super(12,"ddsds");
console.info(123);
this.id=12;
}
}
let man:ManTeacher = new ManTeacher(); interface IBoy{
play():void;
eat():void;
sayHi(otherName:string):string;
} class GoodBoy extends ManTeacher implements IBoy {
play(): void {
console.info("玩游戏")
}
eat(): void {
console.log("吃饭")
}
sayHi(otherName: string): string {
return `你好${otherName} 我叫${this.name}`
}
} try {
new GoodBoy().play();
} catch (error) {
console.info(error);
} //接口的第二种写法 dataInterface
interface IGoods{
id:number;
name:string;
price:number;
} let goods1:IGoods = {id:1, name:"aaa",price:433 }; class Goods {
id: number;
name: string;
price: number;
hello:number;
constructor( ) {
this.id = 1;
this.name="wangwu";
this.price=222;
this.hello=333;
}
}
let g2:IGoods = new Goods();

  ToDolist示例

//let template:string=``;

class ListItem{
constructor(public title:string,private state:boolean=false){
this.rander();
}
public domHtml:JQuery=$();
public rander(){
let dom = $(`<li><span >${this.title}</span><span class="btnDone">完成</span></li>`);
dom.find(".btnDone").click(()=>{
this.state = true;
this.domHtml.find("span:first").addClass("deleteLine");
});
this.domHtml = dom;
}
} class ItemManager{
private static list: ListItem[] = [];
constructor(){
}
public add(){
var stu = new ListItem($("#txt1").val() as string);
ItemManager.list.push(stu)
$("#todoList").append(stu.domHtml);
}
} let manager:ItemManager = new ItemManager();
$(function(){
$("button").click(manager.add);
})

  安装typescript  cnpm  install  -g typescript  --save

  安装jQuery  cnpm   install  jquery  --save

  监视文件  tsc -w  文件名

ts基础(1)的更多相关文章

  1. TS基础应用 & Hook中的TS

    说在前面 本文难度偏中下,涉及到的点大多为如何在项目中合理应用ts,小部分会涉及一些原理,受众面较广,有无TS基础均可放心食用. **>>>> 阅完本文,您可能会收获到< ...

  2. TS基础笔记

    TS优势 更好的错误的提示,开发中及时发现问题:编辑器语法提示更完善:类型声明可以看出数据结构的语义,可读性更好; TS环境搭建 1.安装node;2.npm install typescript@3 ...

  3. ts --基础类型

    声明js的基本类型1.数字let a: number = 2; 2.字符串let aa: string = "22" 3.数组 (1) 数组元素: let b: number[] ...

  4. TS 基础数据类型

    1.基础数据类型 Boolean布尔值   Number数字 String字符串  Array数组 Tuple元组  Enum枚举   Any    void Boolean布尔值:true/fals ...

  5. Ts基础

    //typeof 用来判断变量类型 var s: string = 'egret'; var isString: boolean = typeof s === 'string'; console.lo ...

  6. TS学习随笔(一)->安装和基本数据类型

    去年学过一段时间的TS,但由于在工作中不常用.就生疏了,最近项目要求用TS,那我就再回去搞搞TS,写一篇记录一下自己学习TS的进度以及TS知识点 首先,关于TS的定义我就不在这描述了,想看百度一下你就 ...

  7. TS学习

    随着vue3.0的即将到来,是时候学习一下TS了 简介:TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类 ...

  8. create-react-app的TS支持以及css模块化

    开始: 利用官方脚手架,搭建react工程.参考:https://react.docschina.org/docs/create-a-new-react-app.html. 过程: 1.暴露webpa ...

  9. (二) 从Angular1到Angular2需要的预备知识

    1. TypeScript语法与ES6新特性 写惯了jQ的话突然从ES5跳到ES6,又是个变形的ES6(TypeScript),学习成本确实不低.不过笔者也是从ng1直接上手ng2,对与很多新特性的积 ...

随机推荐

  1. 一篇迟到的gulp文章

    前言 这篇文章本应该在去年17年写的,但因为种种原因没有写,其实主要是因为懒(捂脸).gulp出来的时间已经很早了,16年的时候还很流行,到17年就被webpack 碾压下去了,不过由于本人接触gul ...

  2. Android优秀github项目整理

    1.照相选相册,裁剪的 library TakePhotohttps://github.com/crazycodeboy/TakePhoto 2几行代码快速集成二维码扫描功能https://githu ...

  3. 关于react router 4 的小实践

    详细代码栗子:https://github.com/wayaha/react-dom-CY clone然后 npm install npm start 分割线 1.这个项目使用create-react ...

  4. Socket 异步通信

    最近在写数据通信的时候用到的东西!希望对大家有帮助 /// <summary> /// 获取或设置服务器IP地址 /// </summary> public string se ...

  5. 【转】简单了介绍js中的一些概念(词法结构) 和 数据类型(部分)。

    1 , javascript字符集: javascript采用的是Unicode字符集编码. 为什么要采用这个编码呢? 原因很简单,16位的Unicode编码可以表示地球人的任何书面语言.这是语言 国 ...

  6. 洛谷 P1490 解题报告

    P1490 买蛋糕 题目描述 野猫过生日,大家当然会送礼物了(咳咳,没送礼物的同志注意了哈!!),由于不知道送什么好,又考虑到实用性等其他问题,大家决定合伙给野猫买一个生日蛋糕.大家不知道最后要买的蛋 ...

  7. CSS中的背景、雪碧图、超链接的伪类样式

    一.背景 1.背景颜色 background-color: red; 2.背景图片 background-image: url("../../img/l1.png"); 3.图片填 ...

  8. Python并发编程之线程消息通信机制任务协调(四)

    大家好,并发编程 进入第四篇. 本文目录 前言 Event事件 Condition Queue队列 总结 . 前言 前面我已经向大家介绍了,如何使用创建线程,启动线程.相信大家都会有这样一个想法,线程 ...

  9. 软件性能测试技术树(二)----Linux服务器性能

    全图: 测试目的: 测试范围&性能指标: 测试与生产环境服务器配置不同的处理方法: 实时CPU监控: 实时内存监控: 实时网络监控: 实时磁盘监控: 万能命令:  Linux下的进程追踪命令: ...

  10. Java CAS 原理分析

    1.简介 CAS 全称是 compare and swap,是一种用于在多线程环境下实现同步功能的机制(可以把 CAS 看做乐观锁).CAS 操作包含三个操作数 -- 内存位置.预期数值和新值.CAS ...