DEV Community

Pelle Wessman
Pelle Wessman

Posted on • Originally published at github.com

3 2

TypeScript 4.5 adds JSDoc template tag defaults

TypeScript 4.5, which is currently a release candidate, includes an exciting new feature for us types in js JSDoc users:

Defaults for template tags, microsoft/TypeScript#45483: @template [T=string]

I found this through when looking for a way to void T defaulting to any when no value was given in this code:

/** @template [T=undefined] */
class ErrorWithCause extends Error {
  /**
   * @param {string} message
   * @param {{ cause?: T }} [options]
   */
  constructor (message, { cause } = {}) {
    if (cause) {
      /** @type {T} */
      this.cause = cause;
    }
    // ...
  }
}
Enter fullscreen mode Exit fullscreen mode

Now it gets set to undefined when no value is provied and my type-coverage got closer to 100%.

And it properly compiles to:

export class ErrorWithCause<T = undefined> extends Error {
    constructor(message: string, { cause }?: {
        cause?: T;
    } | undefined);
    cause: T;
}
Enter fullscreen mode Exit fullscreen mode

I will push this new code to my pony-cause module very soon, just wanted to write this up first 🥳

Originally posted as a discussion in the types-in-js community:

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay