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

Move @types/node and @types/node-fetch to devDependencies #868

Closed
wants to merge 1 commit into from

Conversation

tilfin
Copy link

@tilfin tilfin commented May 28, 2024

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Move @types/node and @types/node-fetch to devDependencies. These type modules are not required for the production build of applications using this library and should therefore be listed as devDependencies instead of dependencies.

Additional context & links

Unnecessary inclusion of type modules in dependencies can lead to bloated production builds. By moving them to devDependencies, we can keep the production build leaner.

@tilfin tilfin requested a review from a team as a code owner May 28, 2024 13:34
@rattrayalex
Copy link
Collaborator

These should not affect production builds if you use a tree-shaking bundler, but are required to provide correct types in some situations.

@rattrayalex rattrayalex closed this Jul 8, 2024
@tilfin
Copy link
Author

tilfin commented Jul 9, 2024

@rattrayalex Thank you for your response.

I would like to point out that tree shaking node_modules, including type definitions, is not a common practice in Node.js projects. Most Node.js applications are not bundled in a way that would allow for effective tree shaking of dependencies.

While it's true that tree shaking bundlers can potentially eliminate unused code from dependencies in browser-based applications, this approach is rarely applied to server-side Node.js projects.

And, could you please elaborate on the 'some situations' where these type definitions are required in production builds?

@rattrayalex
Copy link
Collaborator

These types are not just internally used, they are part of the API exposed by the package, so they must be specified in dependencies – otherwise TypeScript users would get errors when using the package.

You can look forward to the dependency weight going down once our work to remove node-fetch as a dependency is complete! See #402 (though most work is happening behind the scenes there right now).

@tilfin
Copy link
Author

tilfin commented Jul 12, 2024

I understand your intention now. It's because of the imports: { "openai/*": "./src/*" } in package.json, which allows imports like:

import { ChatCompletionUserMessageParam } from 'openai/resources/chat/completions';

I see why it's necessary.

However, I didn't notice this at all because there's no mention of it in the README and VSCode autocomplete doesn't work for these imports.

In my case, I've been using it like this:

import OpenAI, { APIError } from 'openai';
export type OpenAIChatUserMessage =
  OpenAI.Chat.Completions.ChatCompletionUserMessageParam;

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

Successfully merging this pull request may close these issues.

None yet

2 participants