做淘宝客的的网站有什么要求,网站推广文案,宁乡的网站建设,建立门户网站类型推论
TypeScript里#xff0c;在有些没有明确指出类型的地方#xff0c;类型推论会帮助提供类型。 例如#xff1a; 变量xiaoc被推断类型为string
如重新给xiaoc赋值数字会报错
let xiaoc xiaocxiaoc 1111111111111如没有给变量指定类型和赋值#xf…类型推论
TypeScript里在有些没有明确指出类型的地方类型推论会帮助提供类型。 例如 变量xiaoc被推断类型为string
如重新给xiaoc赋值数字会报错
let xiaoc xiaocxiaoc 1111111111111如没有给变量指定类型和赋值会被ts推断为any可以执行任何操作
let xiaocxiaoc 1234
xiaoc xiaoc
xiaoc undefined
xiaoc true类型别名
type 关键字可以给一个类型定义一个名字多用于复合类型
定义类型别名
type str stringlet s:str 小Cconsole.log(s);定义函数别名
import { log } from consoletype str() string
let s :str () 我是小C
log(s)定义联合类型别名
type str string | numberlet s: str 123let s2: str 123console.log(s,s2);定义值的别名
type value boolean | 0 | 213let s:value true
//变量s的值 只能是上面value定义的值type 和 interface 还是一些区别的 虽然都可以定义类型 1.interface可以继承 type 只能通过 交叉类型合并 2.type 可以定义 联合类型 和 可以使用一些操作符 interface不行 3.interface 遇到重名的会合并 type 不行 左边的值会作为右边值的子类型遵循图中上下的包含关系
type a 1 extends number ? 1 : 0 //1type a 1 extends Number ? 1 : 0 //1type a 1 extends Object ? 1 : 0 //1type a 1 extends any ? 1 : 0 //1type a 1 extends unknow ? 1 : 0 //1type a 1 extends never ? 1 : 0 //0