Skip to content

Instantly share code, notes, and snippets.

@pfftdammitchris
Created January 16, 2026 04:25
Show Gist options
  • Select an option

  • Save pfftdammitchris/d248df956b4cdb93c4fd8f92cf8b92e2 to your computer and use it in GitHub Desktop.

Select an option

Save pfftdammitchris/d248df956b4cdb93c4fd8f92cf8b92e2 to your computer and use it in GitHub Desktop.
The Power of TypeScript's Satisfies Operator - snippet-4.ts
type Route = {
path: string
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
}
const routes = {
users: { path: '/api/users', method: 'GET' },
createUser: { path: '/api/users', method: 'POST' },
updateUser: { path: '/api/users/:id', method: 'PUT' },
} satisfies Record<string, Route>
// TypeScript knows exactly what routes exist
routes.users.method // Type is 'GET', not 'GET' | 'POST' | 'PUT' | 'DELETE'
routes.nonexistent // Error! Caught at compile time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment