Strict configuration objects
📖 Scenario: You are building a simple app that uses a configuration object to control its behavior. To avoid mistakes, you want to make sure the configuration object only accepts specific properties and types.
🎯 Goal: Create a strict configuration object in TypeScript that only allows certain properties with exact types. Then, use this object in a function that reads the config and prints a message.
📋 What You'll Learn
Create a TypeScript interface called
AppConfig with properties appName (string), version (string), and debug (boolean).Create a constant
config of type AppConfig with exact values: appName: 'MyApp', version: '1.0.0', debug: true.Write a function
printConfig that takes a parameter config of type AppConfig and prints the app name, version, and debug status.Call
printConfig with the config object and print the output.💡 Why This Matters
🌍 Real World
Strict configuration objects help prevent bugs by ensuring only allowed settings are used in apps, making code safer and easier to maintain.
💼 Career
Many software jobs require writing clear and safe code. Using strict types for configuration is a common practice in professional TypeScript projects.
Progress0 / 4 steps