Inferred Type Predicates with TypeScript 5.5
This have made TypeScript more intelligent
So Typescript 5.5 has launched and as usual it brings a whole lot of new things out for the TypeScript developers. 👇
Among a lot of new changes, one of the most eye-catching improvement is the new ‘Inferred Type Predicates’ that is coming out. This helps TypeScript to intelligently deduce the type of a variable as it moves though the code.
Let me explain this with a simple example. (You can of course dive into the TypeScript documentation to view the whole list of changes with examples.)
Lets assume a list of people and an application where we have to move all the possible ones from their original place to another far away place. Only a few have a mode of transportation.
type Car = {
make: string;
drive: () => void;
};
type Person = {
name: string;
favouriteFood: string;
car?: Car;
};
const people: Array<Person> = [
{
name: "John",
favouriteFood: "Chicken",
car: {
make: "BMW",
drive: () => {},
},
},
{
name: "Phil",
favouriteFood: "Steak",
},
{
name: "Sam",
favouriteFood: "Ratatouille",
},
{
name: "Rick",
favouriteFood…