Try Compiling ts into js!

Transcript

English (Auto-generated)

and what it does. So first of all we need to have a T. S. File and I'm gonna create one. I'm going to click on the new file and there is a new file and now the file name can be anything like I can write the nx dot T. S. It cannot be the Js by the way, it has to be T. S. Okay. But the name can be anything, I mean it can be index, it can be, you know, whatever you want. For now, I'm going with the index and I'm just pressing the line break, I mean in Turkey and then here um we just got the index dot T. S. File and now we can program things and it and we're gonna compile, we're just gonna test how the compiler works. So I mean I'm gonna write you know something like war. I'm going with the basic javascript. That is totally fine. Bar I'm going to write something like you know um name, sorry name Okay, that's awesome. Or let's call it my name. Okay, that, that helped actually. I was writing I was writing name earlier and it is, you know, a reserved character. So you can see that can already declared blocked scoped variables. The name was somewhere declared in the typescript so we just cannot use it. And name is I know the reserved queue board by the way my name. Okay, so this is, you know this is, this looks like the javascript but it is technically typescript which is the super set of javascript. So ultimately we just wrote javascript in the typescript now we just cannot use this file so how to make it usable. Just go to the, you know, the the terminal, you can use the power shell or whatever you want and you need to be exactly in the same folder. I mean, you know we are in the in the introduction to typescript and you just need to write the T sc it is the key command to do anything with the typescript compiler. So TSC and then space and then I'm going to write um what I just want to compile, I want to compile in next on I do not need to write dot yes, because we already have mentioned, we are going to do something with the typescript file so we do not need to mention that the extension. So index is enough. I'm going to press the enter key now and it's gonna take a little time and we're gonna have a new file right here. You can see that the new file, if I click on this new file actually both has seen code. So what is this? I mean why both had the same code basically because you know, it is the simple javascript code. So we compiled it because it was written in the T. S. But because it was simple javascript which is totally allowed in the typescript. So after the conversion it just converted into the javascript because originally it is so we just got no impact and no problem, that's awesome. But now I'm just gonna delete this file Okay and I'm gonna make it something like you know typescript. So I'm going with the string now this is the typescript, we actually have defined the type for this variable, we're going to talk about how the types actually works later but for now just take it as an example. This is the typescript method and this just cannot work in the javascript. Okay, this this thing this what we've added is not the javascript method. So now when we compile it TX index and I pressed the line land break or the inter key I got the index again. Now you can see that the difference in the javascript because that is not the method of the javascript because in the javascript we just don't define the types. So it just converted it into the javascript by simple way with by deleting the the you know, string. It just needed the compiler just needed to make this Centex, you know usable in javascript. So now the java the javascript can use this file or the browser can can understand this file because it's now pure javascript. Okay, that's you know that's a that's a straight thing but let's see if I, you know, I'm going to the next variable water a number. Okay and then I'm writing here number. Okay, so in you know, you need to know in javascript we don't just simply call integer the college number. So I was just calling it ended in the previous cast anyway but it is the number okay, number and equal to now I need to define the number. Like I can write one. It is totally fine. But let's just assume I'm writing a number using you know the the single or double quotes. Now that makes a problem, you can see that it just got the red line because in my brow in my I D E I just defined it this way. I mean you know, so the type string is not assign able to type number, it is literally understanding the problem and it is showing the problem. So now um I just have to be clear about creating a variable and its type. So I mentioned a number, variable should be uh an actual number because of its type is number. So I just write I just wrote one now I'm going there and I'm gonna right now the T S C index again. Okay. And now actually it will be converted because in in theory javascript is, it still understands understands this. But you know in typescript it's a problem. It's a documented problem because in the document you just cannot write anything which is not a number. So here they just showed us the problem too. They found one error which is a number. Okay, the same error. We just got here, the same error we got here. But if I go to the index dot Js now you can see that because you know in javascript we don't define the type so it is the my name is you know whatever uh a number is whatever, but you know it works here. Sorry. So now I think that makes clear that it's still converting because in javascript in theory in javascript, there is no problem if we simply delete that. So you know it works in javascript but it doesn't work in typescript so you should take care of this even it's convertible but you should take care of this problem and you need to solve this, if this is a string then you just need to make it in a string and then there won't be any problem like you know found one error and it will convert it the way it has to be just a thing that you know, we do not need to delete the file every time we need to compile, the old file will automatically be you know replaced with the new ones. So there is no problem. You can say the system will delete the file and update the new code so there is no need to delete it by yourself anyway. So I think you know, we just now know the compiler, well now we're going to talk about something else too and then we are going to move forward until then stay tuned
57 Views 0 Likes 0 Comments

Try Compiling ts into js!

Comment
Leave a comment (supports markdown format)