node-yahoo-finance2 icon indicating copy to clipboard operation
node-yahoo-finance2 copied to clipboard

[docs] Explain the new validation code

Open gadicc opened this issue 5 months ago • 0 comments

Explain the rationale and history.

We use our own custom validators, that provide similar(ish) errors as ajv.

  1. "Fast" validators like ajv and others rely on runtime compilation using new Function(). This is fast but is a blocker for Cloudflare Workers and other (secure) environments which can block this. There are some ways to precompile but they don't have all the same features. To remain fast at runtime without precompilation, we have a custom validator that doesn't cover the entire json-schema spec, but rather, only the few features we need. Speed is particularly important for > 1,000 tests we have.

  2. We tried typebox for a while which had the best DX but unfortunately, was not completely stable at time of use, and struggled with certain TS features we needed. But, the biggest deal breaker is the trend for libraries not to export inferred types (so called "slow types"), because of the performance impact. (They're fine for your own main project, if libraries and libraries they depend on are all inferring, things get slow). It also helps to have clear types to use for tsdoc, etc.

  3. TypeScript is the single source of truth.

Anything else?

gadicc avatar Aug 15 '25 08:08 gadicc