Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript compilation error #175

Closed
monooso opened this issue May 15, 2020 · 3 comments
Closed

TypeScript compilation error #175

monooso opened this issue May 15, 2020 · 3 comments

Comments

@monooso
Copy link

monooso commented May 15, 2020

TypeScript reports the following compilation error, due to this line.

node_modules/@apidevtools/json-schema-ref-parser/lib/index.d.ts:1:76 - error TS2307: Cannot find module 'json-schema'.

1 import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type } from 'json-schema';

@types/json-schema is listed as a development dependency, but isn't installed along with your package.

Explicitly installing @types/json-schema as a development dependency fixes the error.

Is this expected behaviour? I'm pretty new to TypeScript.

@JamesMessinger
Copy link
Member

The way I see it (though I could be persuaded otherwise), type definitions should always be devDependendencies. They're not needed at runtime, and they're not needed at all for anyone who isn't using TypeScript. If you are using TypeScript, then you are take a devDependency on the type packages that are needed to make TypeScript work, including types that are needed by third-party libs.

I'd be curious to hear what other people think about this. I could certainly be persuaded to move types to dependencies, but I suspect that some folks (especially those who aren't using TypeScript) won't like that because it pollutes their runtime node_modules.

@monooso
Copy link
Author

monooso commented May 17, 2020

@JamesMessinger I completely understand your reasoning.

I'm curious as to why I haven't encountered this with other packages. Do you know if installing the types as a dev dependency from DefinitelyTyped automatically takes care of this?

@JamesMessinger
Copy link
Member

Now that TypeScript is rapidly growing in popularity, I suspect this issue will come up more frequently and the community will (hopefully) agree on a standard approach or solution to the problem. 🤞

Installing the types as a dev dependency will solve the problem. I do that in a few of my apps for some third-party libs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants