bouzuya.hatenablog.com

ぼうずやのにっき

typeof a[number]

TypeScript のアレコレはすぐに忘れる。

const a = ["a", "b", "c"] as const; // readonly ["a", "b", "c"]
type A = typeof a[number]; // "a" | "b" | "c"
type A_0 = typeof a[0]; // "a"

const b = ["a", "b", "c"]; // string[]
type B = typeof b[number]; // string

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhjAvDA2gIjmgNDNAjbXYNAXXghlEigG4YB6emAJwFM4ATcAGwE9UMhfEOIkAsACgovAA6sYAQSQxpckADN4KMAFcAtnlbMSdRrkwwAPrgJWiaSavkKA+gAZlTjVrcmGTQUlJKmgYPGV0TBxhaNFTJmhmAEswAHMUcSlZeQAhT2zvPG19Q2N4mESU1MkgA


今日のコミット