denoland / denoland/std

discussion: runtime type-checking

Open
#3,888 12 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

Most functions/methods in the Standard Library do not check the type-check arguments at runtime. However, [some](https://github.com/denoland/deno_std/blob/451efa6243759031be85c55c927cbe5d04472afe/path/windows/extname.ts#L14) do. Aiming for consistency, this begs the question: should we type-check arguments at runtime or not throughout the Standard Library? This question is mostly important for transpilation of browser-compatible modules for the browser. E.g. Fresh islands. There are 3 prominent possible approaches and arguments.

**1. Type-check all modules**
The benefit is that all code, when transpiled, is type-guarded. This is nice but would incur a considerable engineering cost, especially if done codebase-wide. The risk is if this is done but not needed or demanded, that would mean a substantial ongoing engineering cost. This is what Node does. All code would also become dependent on `std/assert`.

**2. Don't type-check any modules (for now)**
It's possible that the demand for type-checking is zero or near zero. In that case, the main benefit of this approach is that it could avoid needless engineering costs. It's also possible that, in the future, there _will be_ a demand for type-checking expressed by the community. This approach would allow us to re-evaluate while being more informed in the future. We would have to clearly state, somewhere in the README, that no type-checking is done, and this fact should be considered for those transpiling code for the browser.

**3. Only type-check web-compatible modules**
This approach meets in the middle of the other two. An engineering cost would be incurred on browser-compatible modules but not on the remainder of the modules.

I'm most in favour of option 2. It's simple and avoids wasting any time on possibly needless type-checking, allowing us to make a more informed decision in the future. It'd require us to perform some cleanups around the codebase, but that wouldn't take too long.

Community, what do we think? Are there other unexplored options? Please let us know.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.