How do I decide whether @types/* goes into `dependencies` or `devDependencies`?

后端 未结 3 1341
花落未央
花落未央 2020-12-04 06:07

I use TypeScript 2 in my project. I\'d like to use some js library, but also typings for that library. I can install types with simple npm install @types/some-library<

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 06:44

    Let's say you're developing a package "A" that have @types/some-module package in devDependencies. For some reason you're exporting the type from @types/some-module

    import {SomeType} from 'some-module';
    export default class APackageClass {
         constructor(private config: SomeType) {
    
         }
    }
    

    Right now Typescript consumers of package "A" are unable to guess what SomeType is, since devDependencies of package "A" are NOT installed.

    In that particular case you NEED to place @types/* package with regular "dependencies". For other cases "devDependencies" are good enough.

提交回复
热议问题