2023-10-01
--
Comparisons of ways of typing in 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 is useful in narrowing down the type from whatever the type was defined in the config type to the actual value - eg. instead of string as the type for username, it will be inferred as "asdf".