If you look at the source code for this, you'll see it's a book talking about nodes and where is this access? Where has it been defined? And so hopefully it gives you an idea of how these code linters are working and what they're doing.
So then we think, relax, we've done that task, take a bit of a break and then get onto our second task, which is introducing generic typing across the code base.
So yeah, so this is something which, I, before I worked at aggrid, this is something that I wanted. I had added my own interfaces in and so as a task I came in and said, can I do this, can I make it better? And so we've got this, I've got permission but now I've got to actually do the work.
The kind of changes that this involves is taking, so I does filter parse params and see we've got this data, as an any, which we want to be a generic. And also we need to pass that generic down to our row node. So whenever someone's accessing data off the row node, they have the correct interface there. So there's a lot of interfaces and there's a lot of chaining of interfaces that would have to go through an update.
So why is this difficult? Well, there's about three to 400 interfaces and types and there's this interface. So it's gonna be possible to do it by brute force but you might miss some or it's just gonna be quite tedious. And that's where I wanted to suggest an even sharper axe to you.
So there's this project called tsmorph. And what this has done is it's taken the TypeScript compiler and it's wrapped those matcher functions with a much higher level abstraction. And so this is gonna make it a lot easier to I guess, write your logic in a way where you don't actually have to know the difference between the different types of node or it's just a variable expression or is this an interface. So it does a lot of the work for you.
So with this, we import ts-morph and we'll point to a ts-config file and that will build us a project. And then from that project, you can say, give me this source file. So here I'm saying, give me the grid options source file. So that gives it to me. And then I can say, well actually give me all the import declarations because I want to know where the files are that contain all of the interfaces used on our grid options. And then we iterate over all those imports, get the source files. And then from each of those source files, we extract all the interfaces. So you can see the code we're writing here because of ts-morph is actually quite straightforward. We're not having to really get nitty gritty, but we're extracting all the information. We're collecting all these interfaces so that we can then reason about them. And then we're going to do something a bit like this. So we've got all our interfaces. We're then going to look for the data property on them. So using this like get property. And then we'll look at the type, say, is that an any type? And then this is the next stage, which probably I should have highlighted a bit more in the slides.
Comments