赞
踩
--incremental
flag--incremental
其实是和--tsBuildInfoFile
联合起来使用的,--incremental
是为我们上一次的compile信息做一次硬缓存,在我们下一次修改项目时会进行信息比对然后减少编译的消耗。--tsBuildInfoFile
指定我们的缓存文件的目录,相对于cmd shell的相对路径吧。
同时--outFile
也会影响--tsBuildInfoFile
的文件位置。
具体链接:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#composite-projects
高阶函数的定义是:函数的参数为另一个函数。
interface Box<T> { value: T; } function makeArray<T>(x: T): T[] { return [x]; } function makeBox<U>(value: U): Box<U> { return { value }; } function compose<A, B, C>(f: (arg: A) => B, g: (arg: B) => C): (arg: A) => C { return (x) => g(f(x)); } //这里的compose B的推导是A的返回值类型, 所以 B 传入 T[] const makeBoxedArray = compose(makeArray, makeBox); makeBoxedArray("hello!").value[0].toUpperCase();
ReadonlyArray
andreadonly
tuples只读数组声明
1.内置lib ReadonlyArray<string>
2.type myReadonly<T> = readonly T[]
3.错误申明 type aaa = readonly Array<boolean>; //第三个声明方式是不行的
利用映射类型声明readonly/writable数组,这是类型更加灵活
type mappedReadonlyArr<T> = {
+(-) readonly[K in keyof T]: T[K]
}
const
assertionsconst
声明直接将变量声明,同时进行类型声明转换为只读类型,使用const
声明推导出的字面量类型不会转为更加泛用的类型。
const a = "1" //type "1"
let a1= "1" //type string
let a2 = "1" as const //type "1"
let a3 = <const> "1" //type "1" 该<>的方式不能在.tsx中使用,很好理解.tsx文件中有很多标签<div>....
使用const
模拟enum
export const Colors = {
red: "RED",
blue: "BLUE",
green: "GREEN",
} as const;
globalThis
相当于为global提供一定的类型声明
// in a global file:
var abc = 100;
// Refers to 'abc' from above.
globalThis.abc = 200;
let
,const
声明的变量不会被添加到globalThis
上
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。