For a long time I reached for type annotations everywhere. Then I kept losing autocomplete on my config objects, and satisfies turned out to be the fix.
The problem with annotations
Annotating a value with a broad type makes TypeScript forget the specific keys you actually wrote. You get safety, but you lose precision.
type Routes = Record<string, { path: string }>;
const routes: Routes = {
home: { path: "/" },
blog: { path: "/blog" },
};
routes.blgo; // no error — any string key is allowedsatisfies keeps both
With satisfies, the object is still checked against Routes, but its own type stays exactly what you wrote.
0 comments
Join the conversation
Sign in to leave a comment.
No comments yet
Be the first to share your thoughts!