2023-10-01
--
TypeScriptの型付け方法の比較
const game: Game = {
name: "League of Legends",
genre: "MOBA"
}const notes = await fetchNotes() as Promise<Note[]>import type { SomeConfig } from 'lib';
const cfg = {
db: "postgres",
username: "asdf",
// ...
} as const satisfies SomeConfigas constと組み合わせると、設定の型で定義された型から実際の値に型を絞り込むのに便利です。例えば、usernameの型がstringではなく"asdf"として推論されるようになります。