2023-10-01
Comparisons of ways of typing in TypeScript
2023-10-01
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 SomeConfig as 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" .