Adding a layer of more explicit typings on top of 3rd party library interfaces

Stephen Cooper - May 18 '21 - - Dev Community

You may have noticed that the typing provided by 3rd party libraries often feels very loose. This should not come as a surprise as to maintain flexibility for all users it is not always possible to provide stricter typings.

However, there is nothing to stop us, within our own applications, adding a layer of more explicit typing on top of the library interface. In doing so we can leverage Typescript to greatly improve the developer experience, as well as encouraging consistently in how the library is used.

To demonstrate the benefits of this approach we will work through two use cases.

  1. Adding type safety to AG Grid column types.
  2. Generating type safe custom builders for the Angular Formly library.

With both of these scenarios we will show how adding an additional level of explicit types prevents bugs and speeds up development.

Continue reading at indepth.dev.

inDepth.dev

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .