|
|
|
|
|
by mcv
2310 days ago
|
|
We switched our project to Typescript about a year ago, because we had to handle a lot of different types of data, and it was nice to know which type you have in your hands. I wrote a bunch of code to parse anonymous JSON objects and turn them into objects of the proper types. We added interfaces for all sorts of things. End result: checks don't work, because all our data is run-time. Most of our parameters are still of type `any`. We need to explicitly specify types everywhere that are either `any`, or they're not actually checked. I discovered recently that someone had accidentally created a type that was conceptually the duplicate of an existing type. One of those should never ever get used, but the code doesn't complain, because it's only encountering this in runtime. So I'm inclined to agree: Typescript doesn't really add what it's supposed to add. It adds a lot of work, without providing the security we expect from it. |
|
Or even without that, your data should be entering the system as type 'unknown'. There's then a validator function that takes in unknown and outputs the intended type.
From there onwards, integrity is guaranteed by typescript, but only if you have the discipline to use it consistently. Otherwise, yeah, don't bother.