as方式推断类型

  1. let anystr:any = "hello world"
  2. let strLength: number = (anystr as string).length
  3. console.log('len ',strLength)

<>指定类型

  1. let strLen: number = (<string>anystr).length
  2. console.log('len2',strLen);