Created
January 16, 2026 04:24
-
-
Save pfftdammitchris/f0bed772cda7ab3891d2e75f0b430f50 to your computer and use it in GitHub Desktop.
The Power of TypeScript's Satisfies Operator - snippet-8.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 RGB = [number, number, number] | |
| type Color = string | RGB | |
| const palette = { | |
| red: [255, 0, 0], | |
| green: '#00ff00', | |
| blue: [0, 0, 255], | |
| } satisfies Record<string, Color> | |
| // TypeScript knows the exact type of each property! | |
| palette.red[0] // number (knows it's an array) | |
| palette.green.toUpperCase() // works! (knows it's a string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment