1

I am constructing an npm module in typescript, which when published will contain the generated .d.ts, '.js' and '.js.map' files. This module will in turn be dependent on other modules eg. react, react-dom. Now my question is, when someone installs my module in their app, How do i check whether the installing app is a typescript or javascript project, and if it is a typescript project how do i automatically install the required typings dependencies specified in my module's typings.json.

If there is something wrong with the approach i am going for here, then any other approach is also welcome.

1 Answer 1

2

With typings, I would suggest you allow your consumers to manage transitive dependencies on their own. That means if you depend on declaration files through typings, don't bundle any declaration files installed by typings. Instead, just bundle your own .d.ts files, and let consumers install declaration files on their own through typings.

If you use TypeScript 2.0 and later, you can instead just use npm and @types for your dependencies. See more about @types on the official TypeScript blog post.

For instance, if you depend on the react package, then you should just add @types/react to the dependencies field in your package.json

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

Comments

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.