 Sorry for the delay, the previous speaker had some technical difficulties. And I'm grateful that so many people came for a talk that has word type occurring three times in the title. So, thanks for being here. My name is Chris, I work at Maker Foundation, and today I'm going to be talking about creating type-size dubs with TypeScript and Type Train. So, let me ask you a question. How many people here use TypeScript on a daily basis? Yeah, that's what I was expecting. More than half of our room already. So, in the last few months, the years even, we have seen this tremendous growth of TypeScript popularity, and recently it even got more popular than well-established languages like Ruby, for example. And we see like steady growth on NPM and so on and so on. So, basically TypeScript has this huge company kind of itself called Microsoft, and there's a lot of workforce working on language itself and on the whole tooling around. So, for example, Visual Studio Code was for many people an entry thing, an entry drag for TypeScript because it worked so well. So, for those who don't use TypeScript, let me give you more or less what to expect from the language itself, some ideas behind it. So, first of all, you can think about TypeScript as a JavaScript with types, and the only twist in this explanation is that the type system is totally different from the one that you would find in classical object-oriented programming languages like Java or C-sharp. So, first of all, it features structure typing. So, imagine you have two types with like interface named and interface first named property of a string type, and in TypeScript, these types are interchangeable, so you can assign one to another. So, this is totally unexpected for a Java programmer which has nominal typing. So, this is totally doable in TypeScript, but it's not possible in classical OOP languages, and you might be wondering about dark picture on the right side, dark image. So, if you're a JavaScript programmer, you might be familiar with dark typing concept. So, the idea is just as follows. If it works like a duck, if it works like a duck, then probably it's a duck. So, you don't need to know the exact shape of entity that you're interacting with if it's just enough if it answers some comments and say, and that's why we have duck, that's typing on the right side. So, structure typing is like a duck typing, but during compile time. So, then we have TypeScript features advanced type level programming features. So, basically it allows us to transform types during compile time in like unimaginable way. So, here we have a complex object type which has like some nested properties, we have some arrays nested and so on and so on. So, we can use some generic type, like for example, deep parser coming from the helper library called TS Essentials and essentially, and we're going to get like an object with all properties marked as optional, recursively. And this is pretty awesome, like, you know, you can have a config which is like strict and then we can have like, you know, some defaults and then make automatically user input which is like optional of this config object. And finally, we have gradual typing. This means basically that we don't have to type our application 100% correctly. Of course, you should try to have this, we can come up with type coverage metric which basically means like we can count the number of symbols in our programs that are typed as any, any means that it's really untyped and divided by all the symbols in our program and we can come up with this presentation how your program is typed. And there's this tool TypeCov which does it for us. And basically, this allows us to just fall back to JavaScript and we don't have type coverage or we don't have type information or we just don't care about types in this specific place but of course it should be used as this as possible. So now let's talk about how, what are the challenges about TypeScript and web-free and Ethereum ecosystem challenges. This should not happen. So obviously... Okay, I know. So that was the human part anyway. So now I created like a simple web-free JS called snippet. So here we, so web-free JS is a library written in JavaScript. It's not TypeScript enabled. So here, even though it's a TypeScript file, we use it as it's marked as any. We don't have any type information about it but we can still use it and just operate like if you... and just write code that would write normally in JavaScript. So if you're like really desperate, you can still use it like this. So for example, here is when we're getting like... when we're creating web-free it's any, when we're getting the block number it's any, we're loading API to interact with smart contracts that die contract on the mainnet. It's again any and you know, everything is any. Like you do in JavaScript. So something you are happy with this. But basically this, like TypeScript in this case doesn't help us that much. Like, you know, it's there but when interacting with blockchain it's like dying. So the easiest approach here is to load typings. So typings is just like external type information that was provided by community usually and it just provides this type information for library written in JavaScript. And there are typings for web-free. Usually you would install it by you are at types web-free. Web-free, but we don't have internet connection so I'm going to just load a git snapshot that I did before this talk. And the only change in the code is that the way that we import library instead of using require we use ES6 style imports and then suddenly our code is properly typed almost. So the web-free is properly typed. We can see that the block number is now number. As we expected we get like normal code competition and so on and so on. But when we interact with a contract deployed on the mainnet we load this API on the fly, this is important bit because really this contract is a dynamic structure. It changes depending on the API that you load. So basically these methods are like type but only a little bit. You see here that balance of this type is just take some arguments, the array of arguments. So it's not really properly typed. And return type is again any, which in fact is big number. So it would be cool if it would say to us that it's big number because people are often thinking that it's just number and try to use class on it and they just get an error during ground time, which sucks. So how do we fix this? So typing says this limitation like it lacks API changes as well so if there's a change to Web3.js library then typing needs to be changed by someone later. And as mentioned before it doesn't work with dynamic interfaces like load API and then we generate a wrapper on the fly during the round time so it's impossible to type. Solution for this problem is to generate typing from the fly. So basically we can gather API files from our project upfront before combining it with TypeScript compiler and in the separate build step just generate these typing types. So basically DTS files. And this is exactly what TypeChain does. So another twist here is that we need to generate typing specific to the Web3 like blockchain access library so people using Web3.js the API of a smart contract wrapper is slightly different than from etters or from truffle and so on so basically TypeChain gathers all the APIs gathers like the target that you want to use so for example you specify that you use etters and it generates these DTS files for you. So let me show you how this works. So again we would just do the type train and specific target so in this case we want to load target called Web3 because we're using Web3 now etters and then this is a CLI tool that you could make like a post-install book or anything but here we're just going to run it directly so you can see it running good. So basically you specify the target as I mentioned can you see? You specify target and you specify the API files in this case it's just one file but it supports block patterns and so on and so on and basically we can see that we generated some general types for Web3 and here C20 DTS file and now in the code of our application we need an explicit cast for this interface that was generated because it's just impossible to guess like to make a connection between the address that can be random during the compile time with the typing so here we just need something like this explicit cast and voila. Now DAI is your C20 token and balance is big number as you would expect and we're getting proper code competition here so these are all ERC20 plus some others methods that DAI contract has and as well as events should be somewhere here so it supports events as well and so on We can also browse a little bit this typing that was generated so basically you can also see that sometimes it allows us to specify either number or stream because this is what Web3 allows us, Web3.js allows us to do so these typings are really convenient and they are as open as possible like if there are some conversion happening you can see it here as well now we don't have to be super strict about some things if you don't want to Okay so in general type chain works perfectly with any IDE it supports TypeScript, it supports type chain generated wrappers it supports officially three different targets so it's Web3, 1.8 Ather's.js and Truffle it supports custom targets so for example imagine that you're not developing a DAB you're developing a protocol and you want to have a generated library to use by different developers and you want to have come up with your own interface hide some metals, whatever you can generate it automatically by providing your custom target it just takes first API and generates some code and by the way it can generate even code in different languages than TypeScript it's a very general interface and basically then you can just hide implementation details from the users of your library you could swap internal Web3 like blockchain access library without affecting your clients and so on and so on type chain has full ABA version 2 support so you know things like structs things like fallback functions or overridden functions now works now work and it supports events as I've shown before and what's pretty cool that it works with Truffle so we can do smart contract development not DAB development only so here I have this example of simple Solidity contract it's like type Truffle project with some simple Solidity contract and it has some dummy functions we have some tests here and it's super nice now to write this because we have all this code competition so we don't need to guess then the method names you don't need to change files to be sure what's the name of the method and what's cool is that if we introduce a change to the Solidity code like let's say we rename say hello to screen hello and we regenerate or we don't and we regenerate the wrappers we're gonna find automatically without running our tests we're gonna find breaking changes so if you do lots of smart contract development just faster to find breaking changes like this it just saves a lot of time and by the way if you use something like a similar tool to Truffle but using errors it works as well because it can generate better style so recently it's still in beta really I was about to release it today because it works very well people test it in the red but they don't have retirement access here really so basically type train version 1.0 features a few new additions so if you use it before and now the targets are extracted as a separate packages which is much nicer because you can even create your own package your own target without polluting the type train repository the ABI parser is much nicer so you might be wondering why do we have a ABI parser at all so basically we can parse JSON style ABI to something typesafe like discriminated unions in typescript speeds up writing the code generation part a lot and it's just less error prone and basically the architecture of type train now we assemble it with the generator compiler architectures where you have this processing in pipeline so first we parse ABI and then we do code generation and this basically means that code generation is just a group function that takes ABI and returns some strings without AIO and so on so it's as simple as possible and I want to talk a little bit now about ETMTS organization that I created more than one year ago which is like a family for typescript related projects typescript and Ethereum related projects so Arcturg was helping me for a long time and recently joined like as an offshore maintainer and we have more than 20 community contributors to type train just a question how would a type train can help us build a user interface for developers to test our smart contracts Can we return to this question when I'm done because I'm running out of time and we have time for questions at the end so type train is already used by well-known companies like Maker now we find Chainlink and so on so it's not like no type project that one uses it's really used in a while and Gitvine also sponsored like many bounties to inject some cash for external developers to help us with exact issues and basically that's it that's my Twitter handle you can follow me on Twitter if you would like to