Created
January 16, 2026 04:24
-
-
Save pfftdammitchris/fb045e48a27b25881377bad299040e97 to your computer and use it in GitHub Desktop.
The Power of TypeScript's Satisfies Operator - snippet-9.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 Endpoint = { | |
| url: string | |
| method: 'GET' | 'POST' | |
| } | |
| const endpoints = { | |
| getUsers: { url: '/users', method: 'GET' }, | |
| createUser: { url: '/users', method: 'POST' }, | |
| // Forgot an endpoint? TypeScript can help if you use a stricter type | |
| } satisfies Record<string, Endpoint> | |
| // Later, you get full autocomplete | |
| fetch(endpoints.getUsers.url) // '/users' - literal type! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment