AssemblyScript is a statically-typed scripting language that compiles to WebAssembly, using TypeScript-like syntax but requiring explicit type conversions and glue code for JavaScript interoperability; the development workflow involves installing the AssemblyScript compiler, writing TypeScript-style code, compiling to .wasm files, and using libraries like as-bind to create import objects that enable calling JavaScript functions from AssemblyScript.
AssemblyScript for Beginners: Compile TypeScript to WebAssembly
Added:alright guys so today we're going to be taking a look at assembly script now a simple script is um another scripting language you can convert to web assembly now you don't need to know a web assembly or anything to go ahead and follow this tutorial now in this video we're going to be loading it from node instead of the browser but just know that you could also have loaded this from the browser and if there's enough people that is interested in this i will go ahead and show you how to load this into browser because it's not that difficult now the first thing you'll have to go ahead and do is to install assembly script now once you've gone ahead and done that a lot of people also recommend you to install the assembly script loader which is a library that will go ahead and load that web assembly into your javascript now i think it's a bit weird right now so i'm using s bind instead just know that you could have loaded this using their simply script loader but i've gone ahead and decided to use as bind instead because it does go ahead and make these binds if you don't know what i'm talking about don't even worry about it just know that normally you cannot just put in a string or just extract the string you'll need a pretty weird glue code in between which i just think is unnecessary when you can use this library called as bind the next library we are using is fs and also notice that we're using the new import syntax and if you are not used to using that in your note application then you can go ahead and follow the link in the description which is a video to max programming he has just done a video on this and he's going to show you how to actually use this import syntax in node the next thing we have is an asynchronous scope and then we are reading in this wasm file which is a file that we're going to be generating using the simply script compiler then we are making an instance of this wasn't file and by passing in something called the import object the import object is an object that will go ahead and define some like a class almost in assembly script which we can then go ahead and access so it means that in our assembly script we can actually go ahead and call the method log and that will actually go ahead and run a console.log so it means that we can directly run javascript code from our assembly script code which is actually really really cool you do need some glue code for this like we need this file over here but i will go ahead and show you that later then we go ahead and run that main instance and pathing the parameter bob now this is something i've made print name so let's go ahead and actually take a look at this utility thing if you have wondered by the extension ts and you're like what are we doing typescript or what no we're not doing typescript but essentially they're using the same extension and also if you have ever programmed in typescript it's going to be very similar so what this empty script has done is they have taken typescript and said well it's a nice syntax and then they have actually gone ahead and we implemented that but of course with different types and stuff like that because assembly script is a statically written language and typescript isn't necessarily statically written but assemblyscript is so they've gone ahead and make some adapting code and stuff like that and they're made some new types and stuff like that and i will go ahead and leave the links to all this where you can go ahead and learn this i will also leave the link to google video which google developer teams have made highlighting this entire process but essentially we're making this glue code here and all it does is that it defines that at runtime we'll go ahead and have this lock function which we can run passing in a string and it will return a void so this is just something we need to do and we're just telling the static one that just ignored that it doesn't exist for now it will exist at runtime then in our main.ts file we'll go ahead and actually load that log function in and you can see the code is actually pretty simple if you've ever done typescript then you know what i mean and but i thought we'll go ahead and actually compile this and also show you how to actually add a parameter that will be different from typescript so to go ahead and actually compile this and get this wasom file you will have to run this i'll also leave it in the description as well because it's a bit long and that would be really annoying to type you know you can just switch out these names here i think it's a pretty self-explanatory function now this here is just loading some of the ass bind glue code to make that as bind work and there we go now it has made this wason file and now we can actually go ahead and run our code and there you go and you can see that that actually comes from here now let me go ahead and for instance just add a number so because this is not typescript but visual studio code thinks it typescript we are going to be getting an error but it is not an error and i'm reading this writing this completely wrong here we go there we go this is not going to show up as an actual type but it is an actual type because this is not typescript this is assembly script so that will work it's just you can get a package for it so it doesn't highlight these errors but i just thought they wouldn't really be necessary so then we can go ahead and actually pass in this number and i mean there's not really going to be a a bigger point to this we're just going to be adding this number so you can go ahead and see that it is actually not typescript and and then of course we will have to pass in a number here okay and we have of course have to compile this because it is not you know something that will just be compiled on runtime now guys i did this on purpose because what we'll actually get is you can see that it cannot convert these types so if you are coming from a dynamically written language you might assume that this will just be automatically converted but it won't and that is you know where i don't necessarily like statically written languages yes they are much more secure but you just have to add all this code all of the time and there's no automatic conversions but i mean it is more safe because you would essentially not be able to run this code unless you actually explicitly define that well yes this is a number but i want it to be a string but all you have to do is just run two string and then this will go ahead and work and there you go so notice that it does say that there is an error but there isn't and there you go now we're passing in the number five and we can of course change this number and that would of course change now guys that was pretty much it for today i will go ahead and leave all of the links in the description as well as this run command here so you can go ahead and compile it and if you have more questions and you are there's some things that you i think i went over a bit fast go ahead and watch that google talk because they talk a bit more in detail on what all these things are and it's the video i've watched to actually know how to do this but generally i think it's actually a pretty easy language to learn now i haven't done too much in the language but it seems like a pretty easy language to learn and yeah guys that was it for today i hope that you enjoyed this video and hopefully see you in the next one
Up Next

Optimizing Image Rotation with Loop Tiling | HTTP 203
@ChromeDevs
28.4K views•2019-03-19

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science





























![WebAssembly - Tutorial and Performance testing - [AssemblyScript to WASM]](https://i.ytimg.com/vi/gCT9ebtTzqw/maxresdefault.jpg)






