3 ms·
The code that you locally control and own you can have strong confidence in and type checking can be very valuable. Anything brought in at run time (say a third
by city41 5y ago
The code that you locally control and own you can have strong confidence in and type checking can be very valuable. Anything brought in at run time (say a third party lib loaded via a script tag or data fetched from an endpoint) you have no guarantees at all about what it will actually be. You can still use TS to your advantage here and type the third party code/data in such a way that will cause the compiler to encourage you to be more defensive, such as using the unknown type.
- eatonphil 5y agoJust because you wrote user input code or an HTTP client does not mean that the results of it are trustworthy. So no I would not agree that even your own code is trustworthy. If it's your own code that does no IO then yeah it's more ok to trust TypeScript.
- city41 5y agoThe HTTP client itself is trustworthy to the extent that static code can be. The data it acquires through requests is not. Same with user input code. You can trust your implementation to the extent of static type checking and analysis. You can't trust anything a user entered into your system. Those are examples of the externals that I stated you can't trust.