3

I have installed packages via npm like

npm i simple-peer
npm i @types/simple-peer

and then referenced it in angular.json like

"scripts": [
    "./node_modules/simple-peer/simplepeer.min.js"
],

Simple-Peer is working fine but unable to get intellisense.

How it is possible?

WasiF
  • 26,101
  • 16
  • 120
  • 128

2 Answers2

3

You're quite close as you have already installed @types/simple-peer

Now try creating a declaration file named typings.d.ts in the src folder or whatever the root of your project is.

Then type the following in the newly created typings file:

declare var SimplePeer: import('simple-peer').SimplePeer;

In main.ts, place the following line at the top of your imports (just to keep it separate)

///<reference path="typings.d.ts"/>

In your ts component, you should be able to import (etc):

import { Instance, SignalData } from 'simple-peer';

In my case, I'm only using Instance as other usage just didn't make sense when strongly typed. So, I have peer as a type of Instance as shown:

peer: Instance;

Now you should be able to explore your options via intellisense. Let me know if this still didn't work so I can check properly as I implemented this a while back.

Also, if you managed to improve usage, share such improvements.

Hope this helps. Thanks

For more information on declaration files: https://angular.io/guide/typescript-configuration#typings

Tobi Teps
  • 160
  • 1
  • 4
0

Declare the line below at the top of your component or service.

declare var SimplePeer: any;

Now you are ready to use it anywhere like

let peer = new SimplePeer({ initiator: true, trickle: false })
Masum Billah
  • 2,209
  • 21
  • 20