Test Your JavaScript and TypeScript Documentation with Deno

submited by
Style Pass
2021-05-23 08:30:09

For Deno version 1.10 I introduced the first of milestone for documentation testing with type checking of your documentation blocks.

I ran out of time for Deno version 1.10, final days before shipping was filled with sniffles, fever and fatigue so what we shipped in that release was a stripped down version of what I had implemented as a proof of concept but wasn’t willing to ship it just yet.

The syntax is pretty straight forward, to make a code block executable it just needs to be a fenced code block. Attributes are used to further specify language and special behavior of the code block:

Sometimes, you need some setup code, or other things that would distract from your example, but are important to make the examples work.

One of the more common mistakes in the wild, and also in our documentation was trivial editor oopsies and out-of-date examples. Compiling your examples will let the type-checker catch all of those errors ahead of time.

Finally, examples can be run to ensure that they actually work as intended. An example is run as a standalone process and considered successful as long as it does not throw.

Leave a Comment