![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
TypeScript
lybinWeb
这个作者很懒,什么都没留下…
展开
-
【TypeScript 笔记记录】基础类型、接口、函数、泛型
文章目录一、基础类型二、接口(interface)三、函数(function)四、泛型(generic)一、基础类型布尔值let isDone: boolean = false数字TypeScript中的所有数字都是浮点数。支持十进制、十六进制字面量,还有ES 2015中的二进制和八进制字面量。let count: number = 10字符串let name: string = 'lyb'数组写法一:元素类型[]:let list: number[] = [1,原创 2022-03-04 17:00:00 · 259 阅读 · 0 评论 -
【TypeScript 类的装饰器】
文章目录类的装饰器使用方法装饰器调用时机可以使用多个装饰器使用工厂函数对装饰器进行包装比较困难的装饰器写法(比较标准)正确的装饰器写法类的装饰器使用方法类的装饰器本身是一个函数接受的参数是构造函数装饰器通过@符号来使用function testDecorator(constructor: any) { constructor.prototype.getName = () => { console.log('dell'); }}@testDecoratorclass Te原创 2021-12-17 11:10:23 · 147 阅读 · 0 评论 -
【TypeScript 描述文件中的全局类型】
/** * ts文件代码: */ $(function() { $('body').html('<div>123</div>') new $.fn.init()})/** * 类型定义文件 用来解决上述代码不识别问题 */ // 定义全局变量// declare var $: (param: () => void) => void;// 定义全局函数interface JqueryInstance { html: (ht原创 2021-10-15 13:49:15 · 519 阅读 · 0 评论 -
【TypeScript 命名空间】
/** * 命名空间 namespace: 让全局变量变为局部变量 * * 将header、content、footer放到命名空间中 * export * * 将page加到home下面 */ namespace home { class Header{} class Content{} class Footer{} export class Page { constructor() { new Header(原创 2021-10-15 13:47:00 · 103 阅读 · 0 评论 -
【TypeScript 类中的泛型】
class DataManager { constructor(private data: string[]){} getItem(index: number) { return this.data[index] }}const data = new DataManager(['1'])data.getItem(0)/** * 类中的泛型 */ class DataManager1<T> { constructor(private原创 2021-10-15 13:46:17 · 97 阅读 · 0 评论 -
【TypeScript 泛型】
/** * 泛型 generic 泛指的类型 */ function join<T>(first: T, second: T) { return `${first}${second}`}function join1<T,P>(first: T, second: P) { return `${first}${second}`}function join2<T>(first: T, second: T): T { // 返回值也是泛型原创 2021-10-15 13:45:29 · 49 阅读 · 0 评论 -
【TypeScript Enum枚举类型】
enum Status { OFFLINE, ONLINE, DELETED}console.log(Status.OFFLINE) // 1console.log(Status[1]) // OFFLINEconst Status1 = { OFFLINE: 0, ONLINE: 1, DELETED: 2}function getRes(status) { if(status === Status.OFFLINE) {原创 2021-10-15 13:44:38 · 75 阅读 · 0 评论 -
【TypeScript 联合类型和类型保护】
四种类型保护的方法interface Bird { fly: boolean sing: () => {}}interface Dog { fly: boolean bark: () => {}}// ## 四种类型保护的方法 /** * 联合类型 * 类型断言的方式 */ function trainAnial(animal: Bird | Dog) { // animal.fly // 调用公共的 =》 联合类型 //原创 2021-10-15 13:43:04 · 88 阅读 · 0 评论 -
【TypeScript 配置文件】
tsc --init 初始化ts文件,生成tsconfig.json的TS配置文件tsc 编译文件tsconfig.jsonexclude:不编译此项中的文件include:编译此项中的文件files:编译此项中的文件removeComments:将注释在编译的过程中干掉noImplicitAny:不允许隐式的声明anystrictNullChecks:不允许把null赋值给其他的类型rootDir ts文件目标outDir:编译之后的文件目录..原创 2021-10-15 11:30:35 · 108 阅读 · 0 评论 -
【TypeScript 爬虫案例练习基础语法 | parcel打包TS代码】
/** * 爬虫爬取这个页面学习的人数 * 1.npm init -y * 2.tsc --init * 3.ts-node 卸载 :npm uninstall ts-node -g * 4.ts-node 安装 :npm install -D ts-node * 5.typescript 卸载,然后安装到项目中 npm i typescript -D * 6.packge.json 中的 script中增加一个键值对 `"dev": "ts-node ./src/crowller.ts"`原创 2021-10-15 11:27:09 · 127 阅读 · 0 评论 -
【TypeScript class中的getter跟setter】
class Person2 { constructor(private _name : string){}; get name() { return this._name; }; set name(name: string) { this._name = name; }}const per = new Person2('lyb');console.log(per.name);per.name = 'yj';console.lo原创 2021-10-15 11:25:20 · 288 阅读 · 0 评论 -
【TypeScript 构造器constructor赋值用法】
// 构造器constructor赋值用法class Person { // 传统写法 // public name: string; // constructor(name:string){ // this.name = name; // } // 简化写法 constructor(public name:string){}}const person1 = new Person('lyb')console.log(person原创 2021-10-15 11:17:35 · 2758 阅读 · 0 评论 -
【TypeScript interface接口】
// interface 和 type 相类似,但不完全一致interface Person { name: string; //readonly name : 只读 age?: number; //?代表的意思: age可有可无 [propName: string]: any; // Person接口中不仅可以有name age 还可以有其他的属性 say(): string;}interface Teacher extends Person { teac原创 2021-10-09 17:28:54 · 54 阅读 · 0 评论 -
【TypeScript 入门】
文章目录vsCode中使用TS类型基础类型对象类型函数里的类型voidnever解构赋值vsCode中使用TS安装typescript:npm i -g typescript安装ts插件:npm i -g ts-node运行:ts-node demo.js类型基础类型null undefined boolean symbol void// 基础类型 null undefined boolean symbol voidconst count: number = 12;const tea原创 2021-09-24 15:11:20 · 63 阅读 · 0 评论