今日高铁出行

看看typescript

  • annotation 注释

null check

I call it my billion-dollar mistake. It was the invention of the null reference in 1965… This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last 40 years.

—Tony Hoare, 2009

strictNullCheck

const firstName:string = null;

Here, biologist is of type false | string, and while it can be narrowed down to just string in the if statement body, the else statement body knows it can still be a string if it’s "":

let biologist = Math.random() > 0.5 && "Rachel Carson";
if (biologist) {
    biologist; // Type: string
} else {
    biologist; // Type: false | string
}

variables without initial values

let x :string|undefined ;
x.length // error , variables is used before asigned
x?.length //ok
x = "x";
x.length // 1

类型别名 type alias

type RawData = boolean | number | string | null | undefined;
let rawDataFirst: RawData;
let rawDataSecond: RawData;
let rawDataThird: RawData;
  • 类型别名只有在编译成js之前的ts文件中存在
type someType = string | number | undefined;
console.log(someType) //error

联合类型别名 combine type alias

.... 今天坐车,就先看到这吧

总结

做了一天车,累了

  • 看了半天ts书

明日目标

  • [] 11:00-12:00 typescript
  • [] 15:00-16:00 vue3响应式原理看完
  • [] 16:30-17:30 英语