Using clipboardjs in typescript

1.5k views Asked by At

I am developing an application using ASP.NET Webforms and I am having difficulty in using clipboardjs with TypeScript.

What I have tried:

a. Downloaded clipboardjs (https://clipboardjs.com/) and added its reference under script folder.

b. Installed clipboardjs typings using nuget.

c. Installed jquery and its typings and added jquery reference to project.

See the file details below,

enter image description here

Now, when I tried to follow their documentation and put some code, I am getting "Cannot find the name Clipboard" error in typescript.

enter image description here

What am I missing? Any suggestion / help will be greatly appreciated.

1

There are 1 answers

0
Daniel Rosenwasser On

If you're on TypeScript 2.0 or later, you can get declaration files for clipboard by running

npm install @types/clipboard

At that point, if you're not able to just write new Clipboard in your file without getting an error, you need to add "clipboard" to the "types" field in your tsconfig.json:

{
    "compilerOptions": {
        "types": ["clipboard"]
    }
}

This will tell TypeScript to walk up the directory chain and try to find types for the clipboard package in each node_modules folder.