ts check for missing

(1) Joint type: | 

let result: (string | number) = 'hh'
 

(2) Need to add optional function parameters?

function getName (age: number, name?:string):string {
  return `age: ${age}, name: ${name}`
}

If the default value is specified, don't add it? Up

function getName (age: number, name:string = 'xiaoming'):string {
  return `age: ${age}, name: ${name}`
}

The remaining parameter array, and the default value undefined placeholder

function getName (age: number, name:string = 'xiaoming', ...args:Array<number>):void {
  console.log(`age: ${age}, name: ${name}`)
  for (let item of args) {
    console.log(item)
  }
}
getName(13, undefined, 34, 4, 5)

(3) The general DOM is set to any, because I don’t know what DOM type it is

let oButton:any = document.getElementById('btn')

(4) If localStorage is not found, the value is null

let age: (string | null) = localStorage.getItem('age')
console.log(age)

So the code should be written like this

Guess you like

Origin blog.csdn.net/Luckyzhoufangbing/article/details/108699777