HTTP/2 主要特点与优缺点


TS 允许将一些不同类型的变量相互赋值,虽然某种程度上可能会产生一些不可靠的行为,但增加了语言的灵活性,毕竟它的祖宗 JS 就是靠灵活性起家的,而灵活性已经深入前端的骨髓,有时会不得不做一些妥协。
当一个类型 Y 可以被赋值给另一个类型 X 时,我们就可以说类型 X 兼容类型 Y。
X (目标类型) = Y (源类型)
原始类型的兼容性主要关注三点:

curl -o- -L https://yarnpkg.com/install.sh | bash
如需升级,再次运行此命令,然后会出现以下信息:
/Users/xxx/.yarn already exists, possibly from a past Yarn install.
> Remove it (rm -rf /Users/xxx/.yarn) and run this script again.
根据提示,由于已经安装了 yarn,所以需要先删除~/.yarn文件,然后再重新执行该命令,即可安装最新版 yarn。
泛型即不预先确定的数据类型,具体的类型在使用的时候才能确定。本节将学习ts中的泛型函数。
在软件工程中,开发定义良好且可重用的组件是非常重要的,因为这确保了程序的灵活性和长期可扩展性。使用泛型可以创建可重用的组件,一个组件可以支持多种类型的数据,而用户就可以根据自己的需要的数据类型来使用组件。
概述中泛型的概念比较抽象,为了理解什么是泛型函数,我们可以结合一个例子来说明。
如下例所示,identity函数返回传入的参数,但是这个函数的可重用性很差,只能支持number类型。
function identity(arg: number): number {
return arg;
}
为了支持更多的类型,我们可以将参数设置为联合类型或者any类型。
Interfaces can extend one or more interfaces. This makes writing interfaces flexible and reusable.
interface Person {
name: string;
gender: string;
}
interface Employee extends Person {
department: string;
}
let empObj: Employee = {
name: 'Kimi',
gender: 'male',
department: 'Payment',
};
Interface in TypeScript can be used to define a type and also to implement it in the class. The most scenarios can be summarized as following:
In this section, we mainly focus on the object and array type definition using interface. As function type definition will be introduced in Function: Types section.
Interface likes contract which defines the structure of the object, array, function and also class. However, we need to note that the TypeScript compiler does not convert interface to JavaScript. It uses interface for type checking.
在TypeScript项目中,tsconfig.json文件指定了用来编译这个项目的根文件和编译选项,通过自定义tsconfig.json文件中的配置项,可以达到我们想要的编译结果。
tsc
当我们使用tsc命令对项目进行编译时,编译器会从当前目录开始去查找tsconfig.json文件,逐级向上搜索父目录。
下面我们将通过以下三个方面来讲述tsconfig.json配置:
files、include、excludecompilerOptionsextends、referencesfiles指定一个包含相对或绝对文件路径的列表,列举在files中的所有文件,编译器在编译时都会将它们包含在内。
// tsconfig.json
"files": [
"src/core.ts",
"src/index.ts",
]
当配置文件中的files字段值如上所示时,使用tsc命令编译时,src目录下的core.ts和index.ts文件会被编译为core.js和index.js文件。

