Created
January 16, 2026 04:25
-
-
Save pfftdammitchris/8243fcc01419ff315dc160c7c8b92947 to your computer and use it in GitHub Desktop.
The Power of TypeScript's Satisfies Operator - snippet-3.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 ThemeColors = Record<'primary' | 'secondary' | 'danger', string> | |
| const theme = { | |
| primary: '#3b82f6', | |
| secondary: '#10b981', | |
| danger: '#ef4444', | |
| } satisfies ThemeColors | |
| // Validation: TypeScript ensures all required keys exist | |
| // Inference: TypeScript still knows the exact literal values | |
| theme.primary // Type is '#3b82f6' (not just 'string') | |
| theme.primry // Error! Typo caught | |
| theme.warning // Error! Key not in the original object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment