TypeScript's satisfies operator finally clicked for me when I realized it's almost always used for specific implementations of configuration objects. So this lesson walks you through the naive approaches I've taken before and how to solve them using the satisfies operator. After this, satisfies will be another tool in your belt in TypeScript. To clean up all the TypeScript code you have around configuration.
Transcript
[00:00] The TypeScript satisfies operator only clicked for me when I realized that the objects that you use satisfies with are almost always specific configurations of a type. So in this example if we try and type base.config as app.config and then we attempt to pass it into this function which expects development, you'll see that baseConfig and its mode still has the possibilities of development or production. And if you're like me sometimes in these scenarios you'll grab the type and you'll say well maybe it's asAppConfig or maybe down here I can say base config as app config or mode as development and then you just kind of hack away on it until TypeScript stops complaining. But what you can do instead of all of that is remove all this, remove all of this, and if you just tell TypeScript that this satisfies app.config, our error goes away because mode can only be development because that's what we have it as. If you try and reassign base.config.mode to production or anything else it will fail.
[01:00] It can only be development. So that's when Satisfye clicked for me, when I realized I want this configuration to be typed specifically to what I have defined, and also match up with a configuration type.