-1

I'm trying to install typescript library for example howler. I use this command:

yarn add @types/howler

It has been installed successfully. But when I import it with import { Howl } from 'howler' and execute application by vue-cli-service serve, it throws error: enter image description here

If i install just howler without @types it works fine with declare module .... What's the problem, help please.

  • Types aren't usually directly imported like that. You likely need to add it to your tsconfig – Liam Jun 30 '21 at 14:00
  • [Like this](https://stackoverflow.com/questions/39818429/how-do-you-import-type-definitions-from-types-typescript-2-0) – Liam Jun 30 '21 at 14:01
  • I added `howler` to dependencies and `@types/howler` to devDependencies. It works fine. So, why I shouldn't use `add` like this? many popular libraries say to install them with `@types/....` – Stanislau Listratsenka Jun 30 '21 at 14:23

1 Answers1

1

You need to install both howler and @types/howler.

  • howler is the actual code. Without it there is nothing to execute. This typically goes in dependencies
  • @types/howler is the types for that code. There is no executable code in this package, just information about how the code in the howler package works. This always goes in devDependencies since the types are not required in production.

You never use @types/package-name-here alone without the corresponding package installed as well.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337