Typescript Stephen Grider »
function isAddAction(action: CounterAction): action is AddAction return action.type === 'add';
When you use if (isAddAction(action)) , TypeScript narrows the type inside the block. Grider calls this "teaching the compiler your business logic."
You will type fetch(URL).then(res => res.json()) a dozen times. Each time, he stops you. "Does TypeScript know that res.json() returns a WeatherReport ? No. It thinks it's any . You just lost all your safety." typescript stephen grider
class HoldAnything<T> data: T;
This is the "aha!" moment of the entire course. You realize that TypeScript is not a linter; it is a . Step 3: The Type Predicate He then writes a custom type guard: "Does TypeScript know that res
In the crowded ecosystem of JavaScript supersets, TypeScript has emerged not merely as a trend, but as a fundamental pillar of enterprise-grade development. Yet, for many developers, the journey into TypeScript is fraught with frustration. They learn what interface means. They memorize how to append : string[] . But when they open a real project—say, a React app with Redux or a Node.js backend—they freeze. They stare at a red squiggly line under any and feel impostor syndrome creep in.
type CounterAction = AddAction | SubtractAction; You just lost all your safety
He draws a "pie". The generic is the slice of pie you pass in.