Created
January 16, 2026 04:25
-
-
Save pfftdammitchris/cc64f53ffd2a7c8c763cbb96b0b6acbb to your computer and use it in GitHub Desktop.
The Power of TypeScript's Satisfies Operator - snippet-1.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
| // Using a type annotation | |
| const theme: Record<string, string> = { | |
| primary: '#3b82f6', | |
| secondary: '#10b981', | |
| danger: '#ef4444', | |
| } | |
| // Later in your code... | |
| theme.primary.toUpperCase() // Works fine | |
| // But what if you try to access a specific property? | |
| const primaryColor = theme.primary | |
| // TypeScript thinks this is just `string`, not the literal '#3b82f6' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment