『型の強化書』
https://booth.pximg.net/6de62284-1b56-4588-a635-65ef5249e752/i/1317204/d4fe4d53-8d82-4c29-82a6-ab420560e76d_base_resized.jpg
https://booth.pm/ja/items/1317204
吉井健文氏
github
TypeScriptの型システムについて
1章
Object.freeze()
const frozenHogeObj = Object.freeze(hogeObj)
hogeObjをmutableにする
TypeScriptではhogeObjの全てのプロパティにreadonlyがつく
asを使わざるを得ない例
これと同じ
code:ts
const a = {} as Person
a.name = "hoge"
↓こんな書き方あるのか
code:ts
const a = <Person>{}
a.name = "hoge"
推奨されていないらしい
JSXコードに曖昧さを含んでしまうため、
https://twitter.com/moyaminC/status/1212318621566935040
!
コンパイルエラーになるが、文脈的に絶対null、undefinedでないときに使う
ここでも
型の抽象度の上下
any>string>string literal typesなど
string literal typesが最も「抽象度が低い」、詳細な型
派生型 (derived type)の話か
組み込みTypeGuard
型アノテーションありで、選言だけをすると、Union typeが残る
しらんかた p.19
タグ付きUnion Types
p.20
interfaceの一プロパティの型で判別できるのか
べんりだが、ちょっと不便mrsekut.icon
ここの例でのtagプロパティを用意しないといけない
inでの判別も同じく。
Genericsの制約
extendsの話
code:ts
interface A<T extends string> {...}
Tは何でも良いというわけではなく、この例ではstringと型互換性があることが要求される
lookup types
http://js.studio-kingdom.com/typescript/release_note/typescript_2_1#keyof_and_lookup_types
2章 p.27