TypeScript Foundations · 8 min read · Intermediate
Interfaces, Type Aliases & Optional Fields
Define clean object shapes with interface and type, mark optional properties with ?, and protect fields with readonly.
What you'll learn
- Define reusable object contracts using interface and type
- Use optional (?) and readonly modifiers cleanly
- Understand structural typing (duck typing) in TypeScript
TypeScript uses structural typing: any object that has the required properties with matching types satisfies an interface, even without explicitly naming it.
Fill-in-the-Blank Exercise
Interface with Readonly & Optional Field
Make id readonly and bio optional on UserProfile.
interface UserProfile {
id: string;
name: string;
bio: string;
}Live Code Lab
TypeScriptinterfaces.ts
Expected OutputClick “Run Live” to compile with TypeScript 5.6
ts-101 - TypeScript Essentials (5h)
Check Your Understanding
Score: 0 / 1
1. What does adding ? after a property name in a TypeScript interface mean?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.