So, today I try to talk something strange in TypeScript. First of all, let me introduce myself. I'm Luca De Pupol. I'm Italian. I'm a software developer at Niaform, and, if you don't know us, we're an Irish consultant company, but we are based in the US, central Europe, Brazil, and some positions also in India. I love also TypeScript and JavaScript.
I try to run my YouTube channel but in the last time, I don't have too much time for it, and also try to write a post for tech people. I love running, hiking, and animals, especially dogs.
By the way, I want to start with a question, and don't be shy. Who loves TypeScript? Raise your hands, but if you don't like it, you can leave your hands down without any problem. Not all the people! And who loves JavaScript? I hope all, because you are here! But not all! Why? Why are you here? Who loves Java? Why?
Okay. I want to start with small tips. TypeScript loves JavaScript. So if you love JavaScript, you should also love TypeScript. But JavaScript doesn't love TypeScript. If you have a JavaScript code, it can also be a TypeScript code, but if you have a TypeScript code, it's not a JavaScript code. Please remember, before you have to study JavaScript, and then you can move to TypeScript. Always. Otherwise, TypeScript is just magic for you, and at run time, it's a mess. And remember, JavaScript code is the only code that runs in production. So, if you don't know it, your customer called your boss, probably! Okay, and that's it for my tips, and I jumped to the code.
I think this talk is like a sort of example, and stuff that we can do with TypeScript. So let me try to write code with this desk, otherwise, I will show the problem, and I will show the solution directly from the solution folder. So I suppose that if you are working with TypeScript, you start to create the types for your object. For instance, you can have, in this case, the person object, the company object, and in some part, you have a sort of union type, for instance, the user type. That is a union between the person and the company. You start to create your object, the person and the company, you can create a new person from the current person, but in some part of your code, you want to print the user. Okay? But the user can be a person or a company. But you want to be strict, and maybe you want to create a function for the person, and create a specific message for the person, and then create a specific message for the company. And this function accepts a person or a company.
Comments