31st March 2023

Type definitions

I recently faced this error below for a package that I reference to as @somePackage(not an actual package😛)

 '.../node_modules/@somePackage/build/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/somePackage` if it exists or add a new declaration (.d.ts) file containing
`declare module '@somePackage';`ts(7016)

This error comes from your package not using type definitions for typescript. So whatever they return is inferred as any . That is not allowed by our TypeScript configuration (compilerOptions.noImplicitAny defaults to true).

The two potential solutions that the error message gives you are:

  1. Installing @types/hig__typography if it exists. This refers to this awesome repository (and the packages generated from it): https://github.com/DefinitelyTyped/DefinitelyTyped. This wouldn’t work in this case as this only contains type definitions for widely used packages.
  2. Creating a .d.ts file yourself that defines the type. Read more about this here: https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html. Basically this is what happens when you import a module in TypeScript that is written in plain JavaScript.