Created
January 16, 2026 04:25
-
-
Save pfftdammitchris/d248df956b4cdb93c4fd8f92cf8b92e2 to your computer and use it in GitHub Desktop.
The Power of TypeScript's Satisfies Operator - snippet-4.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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