Open xingbofeng opened 4 years ago
tsconfig.json
any
'foo'
this
typeof
& / |
const
as const
extends
in
for
class
enum
DOM
button
HTMLButtonElement
null
const $el = document.getElementById('foo'); // $el的类型是HTMLElement | null const $el = document.getElementById('foo')!; // $el的类型是HTMLElement
String
Number
Boolean
Symbol
BigInt
const str = new String('');
str
string
const str = '';
tsconfig.json
any
类型'foo'
这种字符串可能是一个字符串值,也可能是字符串常量类型this
、typeof
、& / |
操作符、const
声明变量但as const
推断常量、extends
可以用于类继承和接口继承也可以用于限制类型、in
可用于for
循环遍历也可用于泛型遍历class
、enum
这种关键字会同时存在类型空间和值空间DOM
时,确认获取的是button
的DOM节点,可以断言为HTMLButtonElement
null
断言String
、Number
、Boolean
、Symbol
、BigInt
),因为直接声明的基本类型不是包装类型,包装类型是为了方便在基本类型值上提供静态方法和实例方法使用,请勿直接用包装类型实例化const str = new String('');
,这时str
是String
类型而非string
类型,而要用const str = '';