One Thing to Do for Better Programming with TypeScript

WESEEK, Inc.
4 min readJun 14, 2024

--

Introduction

Hi, I am Yuki, an engineer for GROWI, an open software developed by us WESEEK, Inc.

As the title tells, today I will introduce one tip to help you have a better programming experience with TypeScript:

Set the strictBindCallApply to true!!!

What is “strictBindCallApply” ?

  • One of tsconfig's options
  • The default setting is false (without strict checking)

What happens if we keep “strictBindCallApply: false”?

If we keep it as false, the code will not be type safe when using bind, call, and apply.

What do I mean by “not type safe”?

The strictBindCallApply page in this reference is easy to understand and gives detailed explanations.

What’s the problem if it’s not type safe? What’s the benefit if it is type safe?

Here is an example:

As the image shows, the code will produce codes where height is misspelled, value2 is not a number, and so on…

  • In short, DX will fail.
  • Otherwise, lint error occurs in IDE and VSCode when it is type safe, and code completion works.

But some of you might wonder that

We don’t use bind, call, apply, do we? (When do we use them?)

  • Certainly, there are a few occasions when you have to use it.
  • For example, with bind, it is sometimes necessary to pass this when using a third-party library.
    In GROWI development, I used this when writing the remark/rehype plugin.

On the other hand, is there any trouble with “strictBindCallApply: true”?

  • None at all.
    It is always better to set it to true for both new and existing projects.
  • Even in existing projects, bind, call, and apply methods should be working (or should not be working), so it is useful to be able to expose the risk with a lint error.

Therefore,

Why not just use “strict: true”?

It is true that setting strict:true will turn on several options such as strictBindCallApply, strictNullChecks, strictFunctionTypes, and so on, which is the most common type safe setting.

However, it is expected to detect a lot of changes in projects that have been using strict:false, and there is a possibility that new options will be enabled with strict:true as TypeScript is upgraded in the future, so it is not a specific or explicit setting. This raises the concern that strict:true will not be a specific and explicit setting.

Reference

We hope you will change the way you write according to the status of your project.

So, set strictBindCallApply:true (or strict:true) now!

About Us💡

GROWI

In addition, I want to introduce a little more about GROWI, an open software developed by us WESEEK, Inc.

GROWI is a wiki service with features-rich support for efficient information storage within the company. It also boasts high security and various authentication methods are available to simplify authentication management, including LDAP/OAuth/SAML.

GROWI originated in Japan and GROWI OSS is FREE for anyone to download and use in English. For more information, go to GROWI.org to learn more about us.

GROWI.cloud

GROWI.cloud is the online version of GROWI that allows non-engineers to manage knowledge easily without system-building processes.

Besides organizational use, GROWI.cloud is also available for individual use and you can always start with a free trial here. After the one-month free trial, you can change your plan into either the individual, duo, or trio plan, OR continue to use the personal plan for FREE with a maximum of 25 users! Go to price & features to learn about the details.

GROWI.cloud origins in Japan and now also offered in the Philippine and other countries which allows customers to use the service in English.

Go to GROWI.cloud to learn more about us. You can also follow our Facebook to see updates about our service.

--

--

WESEEK, Inc.

WESEEK, Inc, a team of skilled system development professionals. Our blog shares insights on our online wiki service "GROWI.cloud" and emerging IT knowledges.