1

I have an angular project built with nx I want to import standard JavaScript libraries which do not have typescript typings for example I want to install and use cytoscape and cytoscape-context-menus

I get compilation errors such as

error TS7016: Could not find a declaration file for module 'cytoscape-context-menus'. 'C:/dev/armo/armo-ng-app/node_modules/cytoscape-context-menus/cytoscape-context-menus.js' implicitly has an 'any' type. Try npm i --save-dev @types/cytoscape-context-menus if it exists or add a new declaration (.d.ts) file containing declare module 'cytoscape-context-menus';

How can I solve them? I tried to put declaration files but I think my setup doesn't see them.

1 Answer 1

1

since there's no available type definition npm package, you have to write your own. start with the ones you need and continue to build on top of it as needed.

if you like you can share it too as an npm package.

found this article for writing TypeScript type definition files by @dubtypescript: http://blog.wolksoftware.com/contributing-to-definitelytyped

also take a look at how cytoscope is typed from here, borrow their ways: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/cytoscape/index.d.ts

Added a stackblitz to checkout:

https://stackblitz.com/edit/cytoscape-6cyuem?file=src%2Fapp%2Fcytoscape-context-menus.d.ts

Sign up to request clarification or add additional context in comments.

10 Comments

Thank you but it didn't work. Some don't have typings in "DefinitelyTyped". Also I try addeding .d.ts file but still I get compilation erros
@canbax added a stackblitz to check out
thank you for your efforts but for me the important thing is the tsconfig.json file. Stackblitz doesn't have that file. Also, I can't use @types/cytoscape. It breaks many things in my application because I don't use type definitions for many things
should be able to download the stackblitz project and check tsconfigs. although it should still work with standard angular app. you may also manually type cytoscope in similar manner.
I'm still getting the error. The problem is with architecture of nx project. I don't really understand how can I add the typings.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.