1. Why types save demos
4 min
The demo problem
JavaScript lets you move fast. It also lets small wrong assumptions reach your demo.
A value from a form is a string. An API field may be missing. A function may return null when your UI expects text. These bugs often appear only when a judge clicks a path you did not test.
One idea
TypeScript does not make your app correct. It makes many bad assumptions visible before you run the app.
Think of it as a build-time check for your JavaScript decisions.
Bug before demo
This JavaScript looks fine until the data shape changes. A college event app might receive this from a local JSON file or a simple backend.
// JavaScript
function formatEvent(event) {
return event.title.toUpperCase() + " at " + event.venue.name;
}
const eventFromApi = {
title: "HackIndia Meetup",
venue: null
};
console.log(formatEvent(eventFromApi));
// Runtime crash: Cannot read properties of nullType catches it
With TypeScript, you describe what the function needs. If venue can be null, the code must handle it before the build or type-check passes.
type Venue = {
name: string;
};
type Event = {
title: string;
venue: Venue | null;
};
function formatEvent(event: Event) {
return event.title.toUpperCase() + " at " + event.venue.name;
// TypeScript warns: event.venue is possibly null
}