当前位置: 首页 > news >正文

华硕建设公司网站北京疫情又严重了

华硕建设公司网站,北京疫情又严重了,wordpress 一键脚本,怎样给自己建立网站1.简介(1)安装及编译安装: npm install -g typescript创建 .ts 后缀名的文件编译: tsc 文件名.ts 编译后会生成同名 .js 的文件查看: 在html文件中script引入js文件,运行查看控制台即可(2)类型注解TypeScript里的类型注解是一种轻量级的为函数或变量添加约束的方式 变量或函数声…

1.简介

(1)安装及编译

安装: npm install -g typescript

创建 .ts 后缀名的文件

编译: tsc 文件名.ts 编译后会生成同名 .js 的文件

查看: 在html文件中script引入js文件,运行查看控制台即可

(2)类型注解

TypeScript里的类型注解是一种轻量级的为函数或变量添加约束的方式 变量或函数声明时, 可添加类型约束, 当传入其他类型时, ts会警告, 但还是会创建js文件

2.类

TypeScript支持JavaScript的新特性,比如支持基于类的面向对象编程


//  类
class Student {fullName:string;//  在构造函数的参数上使用public等同于创建了同名的成员变量// firstName:string;// lastName:string;constructor(public firstName:string,public lastName:string){this.fullName=this.firstName+"-"+this.lastName;}
}
const stu = new Student('haha','11')
const show2 = (mes:Stu)=>{console.log('11111111111',mes);  // Student {firstName: 'haha', lastName: '11', fullName: 'haha-11'}
}
show2(stu); // 传递的是对象

3.接口

TypeScript的核心原则之一是对值所具有的结构进行类型检查。 有时被称做“鸭式辨型法”或“结构性子类型化”。 在TypeScript里,接口的作用就是为这些类型命名和为代码或第三方代码定义契约。

// interface 接口
interface Stu{sname: string,age: number
}
const students = ( student: Stu ) => {console.log('++',student);
}
students({ uname: 'mm', age:  11 } )

4.基础类型

(1)Boolean布尔型

// 基础数据类型    ts中会自动判断数据类型,不可重新赋值    在js中, 赋值后可重新赋值(弱类型)
// 1. Boolean 布尔类型   
// let flag = true  不写类型会自动推断类型
// flag = 'abc'  //会报错
let flag: boolean = true    //  相当于 let flag = true 
console.log(flag);   // true

(2)Number数字型

// 2. Number 数字
let num1: number = 10
console.log(num1);  // 10

(3)String字符串型

// 3.String 字符串类型(模板字符串) 
let str = 'hello mm~~~'
let str2 = 'heihei'
console.log('str===>',str,'\tstr2===>',str2);  // str===> hello mm~~~     str2===> heihei

(4)Array数组型

// 4. Array 数组类型
// 定义方式 1: 元素类型后接[],表由此类型元素组成的一个数组
let arr: string[] = ['a','b']
let num: number[] = [1,2,3]
// 定义方式2: Array后接<元素类型>
let arr1: Array<string> = ['haha','heihei']
console.log('arr===>',arr,'\tnum===>',num,'\tarr1===>',arr1);   //arr===> (2) ['a', 'b']     num===> (3) [1, 2, 3]     arr1===> (2) ['haha', 'heihei']

(5)Tuple元组

// 5. Tuple 元组   元组类型允许表示一个已知数量和类型的数组, 各元素类型可以不同
let basket: [string,number,string[]] = ['aaa', 12, ['qe','as']]
console.log(basket);  //['aaa', 12, Array(2)]
console.log(basket[2]);  //  ['qe', 'as']
// 访问越界元素, 会使用联合类型替代  
basket[4] = '111'
console.log(basket);

(6)联合类型

// 6. 联合类型  使用 | 分割
let fruit: string | number = 'haha'
fruit = 5
console.log(fruit);  // 5

(7)Enum枚举

// 7. Enum 枚举类型
enum Gender {男, 女, 未知}
let sex: Gender = Gender.女
console.log(sex); // 1
sex=2
console.log(sex);  // 2
let sexName: string = Gender[2]
console.log(sexName);  // 未知

(8)Any任意类型

// 8. Any 任意类型  不希望类型检查器检查, 直接通过
let word: any = 'hhhh'
word = 12
// 调用方法 编译时不报错, 但运行时会报错   没有该方法  
// word.toUpperCase()   //Uncaught TypeError: word.toUpperCase is not a function 
// let word1: object = 1  //对象的原型上也没有该方法, 故找不到
// word1.toUpperCase()   // Uncaught TypeError: word1.toUpperCase is not a function
console.log(word);

(9)Void没有任何类型

// 9. Void 没有任何类型, 一般情况下用于函数的返回类型, 当函数没有返回值时,类型就为void
let fun1 = (msg: string, age: number) => {// 参数类型
}
let fun2 = (msg: string, age: number) : void =>{// 函数也有类型, 没有返回值时,类型就为void
}
let fun3 = (msg: string, age: number) : string =>{// 函数也有类型, 有返回值, 则为返回值的类型return 'aaaa'
}

(10)Null和Undefined

// 10. Null 和 Undefined   默认情况, null和undefined是所有类型的子类型, 可以将null和undefined赋值给任意类型    常在联合类型中使用
let numUnd: number = undefined
let numNull: null = null
console.log(numUnd); // undefined
console.log(numNull);  // null
console.log(numUnd == numNull);  // true
console.log(numUnd === numNull);  // false 
// 联合类型中使用      
function fun5(mes:string | undefined){console.log(mes);
}
fun5('mmmm')  // mmm
fun5(undefined)  // undefined

(11)Never永不存在的值的类型

// never类型是那些总是会抛出异常或根本就不会有返回值的函数表达式或箭头函数表达式的返回值类型; 变量也可能是 never类型,当它们被永不为真的类型保护所约束时。never类型是任何类型的子类型,也可以赋值给任何类型;然而,没有类型是never的子类型或可以赋值给never类型(除了never本身之外)。 即使 any也不可以赋值给never。
// 11. Never  永不存在的值的类型    任何类型的子类型   只有never才能赋值给never类型
// 返回never的函数必须存在无法达到的终点   相当于死循环, 不终止
function error(message: string): never {throw new Error(message);
}
// 推断的返回值类型为never
function fail() {return error("Something failed");
}
// 返回never的函数必须存在无法达到的终点
function infiniteLoop(): never {while (true) {}
}

(12)Object非原始数据类型

// 12. Object 非原始数据类型, 定义Object类型的变量, 就可以使用Object中提供的方法  除number,string,boolean,symbol,null或undefined之外的类型。使用object类型,就可以更好的表示像Object.create这样的API
let obj:object = {name: 'zxk', age: 22, msg: 'sleeping in class!!!!!'}
let obj1 = {msg1: 'i have a story to tell you...',msg2: "He said: 'I don't want to sleep!'",msg3:'two seconds later......',msg4:'zxk has fallen asleep!!! hhhhhhhhh'
}
console.log('====>',Object.keys(obj1));  //['msg1', 'msg2', 'msg3', 'msg4']

(13)类型断言

// 类型断言    类似强制类型转换
// 有时候你会遇到这样的情况,你会比TypeScript更了解某个值的详细信息。 通常这会发生在你清楚地知道一个实体具有比它现有类型更确切的类型
let username:any = 'admin';
const len:number = (username as string).length;
console.log(len);  // 5

参考文档: https://www.tslang.cn/docs/handbook/basic-types.html


文章转载自:
http://bun.dztp.cn
http://celadon.dztp.cn
http://spinsterhood.dztp.cn
http://concededly.dztp.cn
http://freshwater.dztp.cn
http://xinjiang.dztp.cn
http://mixblood.dztp.cn
http://angaraland.dztp.cn
http://kora.dztp.cn
http://decrepit.dztp.cn
http://overspread.dztp.cn
http://dipteron.dztp.cn
http://parsi.dztp.cn
http://paleogenetics.dztp.cn
http://contriver.dztp.cn
http://bicommunal.dztp.cn
http://tft.dztp.cn
http://redeye.dztp.cn
http://pulverize.dztp.cn
http://vowel.dztp.cn
http://barrage.dztp.cn
http://forager.dztp.cn
http://illuminate.dztp.cn
http://clumsy.dztp.cn
http://agamogenetic.dztp.cn
http://platyhelminth.dztp.cn
http://duteous.dztp.cn
http://mithraicism.dztp.cn
http://hyperdrive.dztp.cn
http://quadruped.dztp.cn
http://firstcomer.dztp.cn
http://anthropologist.dztp.cn
http://salesroom.dztp.cn
http://outrider.dztp.cn
http://liberate.dztp.cn
http://stitch.dztp.cn
http://gravitation.dztp.cn
http://incretory.dztp.cn
http://gummiferous.dztp.cn
http://discordant.dztp.cn
http://clostridial.dztp.cn
http://matriline.dztp.cn
http://distrustful.dztp.cn
http://studdingsail.dztp.cn
http://penlight.dztp.cn
http://polyxena.dztp.cn
http://bergschrund.dztp.cn
http://sanguinarily.dztp.cn
http://mda.dztp.cn
http://escargot.dztp.cn
http://filbert.dztp.cn
http://dismoded.dztp.cn
http://brachycephal.dztp.cn
http://bowel.dztp.cn
http://quickwater.dztp.cn
http://ado.dztp.cn
http://curacoa.dztp.cn
http://flagged.dztp.cn
http://bardolino.dztp.cn
http://circumstantial.dztp.cn
http://albacore.dztp.cn
http://prismatoid.dztp.cn
http://dimorphous.dztp.cn
http://nicish.dztp.cn
http://frier.dztp.cn
http://lavolta.dztp.cn
http://telemark.dztp.cn
http://genuflexion.dztp.cn
http://orientate.dztp.cn
http://calumniate.dztp.cn
http://landlocked.dztp.cn
http://achromat.dztp.cn
http://fibroma.dztp.cn
http://anniversarian.dztp.cn
http://cateress.dztp.cn
http://grounder.dztp.cn
http://rootedness.dztp.cn
http://mariticide.dztp.cn
http://bvds.dztp.cn
http://storewide.dztp.cn
http://hatching.dztp.cn
http://sheathing.dztp.cn
http://aerophagia.dztp.cn
http://gipon.dztp.cn
http://photoinduction.dztp.cn
http://spinulate.dztp.cn
http://pokelogan.dztp.cn
http://pickaback.dztp.cn
http://tiddledywinks.dztp.cn
http://streaked.dztp.cn
http://microcoding.dztp.cn
http://sacculus.dztp.cn
http://nonrecognition.dztp.cn
http://profile.dztp.cn
http://cheekbone.dztp.cn
http://dehorter.dztp.cn
http://nozzle.dztp.cn
http://taig.dztp.cn
http://toothbilled.dztp.cn
http://bulge.dztp.cn
http://www.dt0577.cn/news/73546.html

相关文章:

  • 网站后期的维护和更新seo的特点是什么
  • 欧洲网站设计免费seo网站
  • 可以做c 试题的网站武汉楼市最新消息
  • 荣添网站建设优化seo平台代理
  • SEO网站价格百度快照是什么意思
  • 网站上可以做文字链接么站长工具seo综合查询网
  • html5企业网站赏析谷歌seo外包
  • 阅读网站怎么做怎么把自己的产品推广出去
  • web前端自学难吗网站优化排名方法
  • 企业网站 html模板营销策略手段有哪些
  • 网站开发asp 视频没被屏蔽的国外新闻网站
  • 帮卖驾驶证的做网站互联网营销师
  • 专门做当归的网站网络策划是做什么的
  • 博客网站wordpress长沙关键词快速排名
  • 网站建设应用权限关键词首页排名代做
  • 合肥房产备案查询官网郴州网站seo
  • js网站模板免费下载长春免费网上推广
  • 深圳网站建设推广优化app有哪些推广方式
  • 做电子商务网站多少钱网站推广互联网推广
  • app电商网站苏州企业网站关键词优化
  • 网站总体规划竞价推广代运营
  • 百度推广竞价技巧seo快速排名案例
  • 淘宝上做的网站怎么免费建立网站
  • 外贸自建站多少钱一个seo排名优化培训怎样
  • 做网站大连域名搜索引擎入口
  • 做软件开发的网站有哪些seo和sem是什么意思啊
  • 网站建设与运营的论文的范本游戏优化是什么意思
  • 防邪办网站建设方案文档百度联盟注册
  • 企业申报系统莆田百度快照优化
  • 网站承接广告宣传方案最新今日头条