Re:Postgres Audit Tables Saved Us from Taking Down Production
by jackweirdy on Saturday August 12, 2023 @02:51PM
(#37103090)
If a property is a string in your typescript interface but a number in your external service (api, DB, whatever) the typescript compiler would not know
Re:Postgres Audit Tables Saved Us from Taking Down Production
by koolba on Saturday August 12, 2023 @06:46PM
(#37104909)
Or worse if you blindly deserialize JSON and cast it as whatever you want it to be without validation…
Re:Postgres Audit Tables Saved Us from Taking Down Production
by ianlevesque on Saturday August 12, 2023 @08:02PM
(#37105302)
e.g. the norm for typescript use.
Re:Postgres Audit Tables Saved Us from Taking Down Production
by awoimbee on Saturday August 12, 2023 @02:52PM
(#37103100)
Typescript does compile time checking only. Almost all TypeScript programs I've seen just decode JSON received and slap an `as SomethingType`.
TypeScript is not strict, so it's easy to write but you can still get type errors.
Re:Postgres Audit Tables Saved Us from Taking Down Production
by hinkley on Saturday August 12, 2023 @03:27PM
(#37103420)
For instance I am currently trying to file a patch for a TS project. It is advertised as an npm module, which means if you pass a string to a function expecting a number it will happily do string concatenation on it instead of addition. There are no internal checks because TS, but that only works if you call it from TS. Otherwise authors have a false sense of security and make bad decisions.
Re:Postgres Audit Tables Saved Us from Taking Down Production
by geraldwhen on Saturday August 12, 2023 @03:18PM
(#37103325)
That’s what’s class-validator is for. You can ensure your apis are doing sensible things.
Re:Postgres Audit Tables Saved Us from Taking Down Production
by thewix on Saturday August 12, 2023 @05:27PM
(#37104388)
This is why I use codec libraries like zod or io-ts (purify has them built in also) at my boundaries.
Re:Postgres Audit Tables Saved Us from Taking Down Production
by Waterluvian on Saturday August 12, 2023 @04:23PM
(#37103916)
They were just accepting incoming data as-is and typescript won’t do a thing for you.
Ideally you validate incoming data using jsonschema or whatnot.
Re:Postgres Audit Tables Saved Us from Taking Down Production
by delusional on Saturday August 12, 2023 @05:09PM
(#37104250)
In the static analysis space this is a fundamental issue. We can't really usefully reason about the actual system, the state space simply becomes too large. So you have to reduce your problems to some axiomatic abstraction. In type systems we mostly cut those axioms at the system boundary. This is mostly because type systems are often incompatible and therefore can't automatically be analyzed across the boundary.
Imagine some pipe. You can put in some bytes and get some bytes out again. As far as you know, you have to put in 16 bit integers, and you get 16 bit integers out. You put that in your type system:
int16_t communicate(int16_t in);
Now what you don't know is that if you provide the remote system with the integer 0, it will send back a 0, followed by the string "hello world". Your type system can't catch that because you've never told it that it can happen. The axioms the static analysis was built on didn't match reality, and therefore the analysis itself isn't sound.
What does this mean? If you use typescript doesn't it prevent these types of bugs?