使用 --save 或 --save-dev 保存 npm @types 类型 [英] Saving npm @types typings with --save or --save-dev

查看:102
本文介绍了使用 --save 或 --save-dev 保存 npm @types 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TypeScript 2 建议对类型使用 npm.在声明文件的未来.

TypeScript 2 recommends using npm for types. In The Future of Declaration Files.

例子是:

npm install --save @types/lodash

我的问题是是否应该在应用程序中使用 --save-dev,因为 TypeScript 是被转译而不是部署的?这篇文章的一些评论提到了类似的,但我看不到任何答案.

My question is whether --save-dev should be used in an application, because TypeScript is transpiled and not deployed? Some comments on the article mention similar, but there is no answer I could see.

也许 --save 在库中有用以在其他人安装您的库时拖动类型?

Perhaps --save is useful in a library to drag around the types when others install your library?

我是否遗漏了其他有用的东西?最佳实践是什么?谢谢.

Am I missing something else this is useful for and what is the best practice? Thanks.

推荐答案

来自 Microsoft/types-出版商#81:

在编写简单的应用程序时使用 --save-dev 很好,并且它不会被用作图书馆.问题出现的时候你可能有依赖性.如果您将类型声明存储在devDependencies,您的消费者不会自动获取您的类型声明.然后他们必须手动添加您的声明文件依赖项作为他们的 devDependencies.

Using --save-dev is fine when you're writing a simple application, and it won't be used as a library. The problem comes along when you might have dependencies. If you stored your type declarations in your devDependencies, your consumers would not automatically get your type declarations. They'd then have to manually add your declaration file dependencies as their devDependencies.

鉴于破坏消费者比稍微大一点的问题更严重包,我们已经在我们的文档中做了 --save 默认值.

Given that breaking consumers is a worse problem than slightly-larger packages, we've made --save the default in our documentation.

这篇关于使用 --save 或 --save-dev 保存 npm @types 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆