Object Properties
TypeScript โฉ
Optional
็ถๅฎฃๅ x?: T ๆ๏ผx ็ๅๅฅๅฏฆ้ไธๆฏ T | undefined
readonly
readonly ่ const ็ไฝ็จๅทฎไธๅค๏ผๆไฟ่ญท Primitives ไธๅๆดๆน๏ผไฝๅฐๆผ Object ไพ่ชช๏ผ้็ถไธ่ฝๆดๆน็ฉไปถๆฌ่บซ๏ผไฝๅฏๆดๆนๅ ถๅฑฌๆงใ
readonly properties can be modified via aliasingโ๏ธ
Index Signatures
TypeScript ็ index signature ้กไผผๆผ Swift ็ subscriptใ
An index signature property type T must be either โstringโ or โnumberโ.
It is possible to support both types of indexers, but the type returned from a numeric indexer must be a subtype of the type returned from the string indexer. This is because when indexing with a number, JavaScript will actually convert that to a string before indexing into an object. That means:
a[100] === a["100"]
Last updated