随笔分类 - typescript
学习typescript之后整理而成的章节笔记。
摘要:// tsconfig.json outDir: "./build"; // 打包编译后的文件放置位置 安装: npm install nodemon -D 配置: //package.json "scripts": { build: "tsc -w"; // w: 改变代码时自动编译代码: sta
阅读全文
摘要:interface Bird { fly: boolean; sing: () => {}; } interface Dog { fly: boolean; bark: () => {}; } // 类型断言的方式 function trainAnimal(animal: Bird | Dog){
阅读全文
摘要:abstract class Geom { getType() { return "Gemo"; } width: number; abstract getArea(): number; // 抽象方法 } class Circle extends Geom { getArea() { return
阅读全文
摘要:class Person5 { constructor(private name: string) {} get getName() { return this.name; } } const person5 = new Person5("dell5"); console.log(person5.g
阅读全文
摘要:// private protected,public 访问类型 // public 允许在类里面或者外面调用 // private 允许在类内被使用 // protected 允许在类内以及继承的子类中使用 class Person3 { protected age: number; public
阅读全文
摘要:// 如何定义一个类,如何在类里面定义属性和方法 class Person2 { name = "dell"; getName() { return this.name; } } // Perso2是父类,Teacher2是子类 class Teacher2 extends Person2 { ge
阅读全文
摘要:interface Person2 { // readonly name: 'string'; // 只读 name: string; age?: number; // 可在可不在 [propName: string]: any; // 可有其他字符串类型的 下面的直接传入对象里面的sex就不会报错
阅读全文
摘要:// 数组和元素 const arr: (number | string)[] = [1, "2", 3]; //数字或者字符串 const stringArr: string[] = ["a", "b", "c"]; // 字符串 const undefinedArr: undefined[] =
阅读全文
摘要:function add2(first: number, second: number) { return first + second + ""; } function add(first: number, second: number): number { return first + seco
阅读全文
摘要:type annotation 类型注解,我们告诉 ts 是什么类型type inference 类型推断, ts 自动尝试分析变量类型,如果 ts 能自动分析类型我们就什么都不需要做,如果不能我们就需要使用类型注解 let count: number; //类型注解,直接声明类型 count =
阅读全文
摘要:// 基础类型 null, undefined,symbol, boolean,void const count: number = 1123; const teachername: string = "ll"; // 对象类型 const teacher: { name: string, age:
阅读全文
摘要:基本类型,例 1: const count: number = 2019 这里我们对静态类型做更深层次的理解,count 是一个 number, 当 count 具备了 number 的静态类型之后,这个变量会具备 number 类型所有的属性和方法。 这时候你使用 count 的时候,在 coun
阅读全文
摘要:安装 npm 全局安装 typescript 命令,npm install typescript -g, 需要具体版本号可在 typescript 后面直接加@XXX,npm install typescript@xxx -g。 运行 直接在终端运行 node demo.ts 会报错,需要先运行编译
阅读全文
摘要:Ts 中文网址:https://www.tslang.cn/ TypeScript 的定义:TypeScript 是 JavaScript 类型的超集,它可以编译成纯 JavaScript。typeScript 可以在任何浏览器,任何计算机和任何操作系统上运行,并且是开源的。 以下分别是 js 与
阅读全文
摘要:typeScript 课程记录安排: 此次课程记录分为四个阶段: 阶段一 TS 基础语法 爬虫功能开发 阶段二 TS 语法进阶 项目接口开发 阶段三 TS 高级语法 项目代码重构 阶段四 项目前端开发 课程总结 课程知识点有: 静态类型,类型注解,类型推断,泛型,类型定义文件,模块化,打包编译,装饰
阅读全文