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

fix(react): move types to devDependencies #8644

Merged
merged 3 commits into from
Mar 13, 2024
Merged

fix(react): move types to devDependencies #8644

merged 3 commits into from
Mar 13, 2024

Conversation

Pessimistress
Copy link
Collaborator

@Pessimistress Pessimistress commented Mar 13, 2024

Non-TypeScript users should not be forced to install types

Change List

@Pessimistress Pessimistress changed the title fix(react): move types to devdeps fix(react): move types to devDependencies Mar 13, 2024
@coveralls
Copy link

coveralls commented Mar 13, 2024

Coverage Status

coverage: 84.082% (+0.2%) from 83.897%
when pulling f4cd48f on x/deps
into 89aa8d0 on master.

Comment on lines 37 to 45
"peerDependencies": {
"@deck.gl/core": "^9.0.0-beta",
"@types/react": "^18.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0"
},
Copy link
Collaborator

@donmccurdy donmccurdy Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any part of our public API exposes these types, I believe they should be in either dependencies or peerDependencies. Example:

import { PureComponent } from 'react';

export class Foo extends PureComponent { ... }

Unfortunately, that does mean installing types is imposed on non-typescript users, but those packages should be small.

Reference:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning is this

  • If someone uses typescript with React, then they must already have the react types installed
  • for someone not using typescript, no lib check will be performed, and all .d.ts files in the dist directory will be ignored anyways

If react is in peer dep then its types must be in peer dep too, as their versions need to match. (I just noticed that we are using ^, it should be >=) Which means non-typescript users have to manually add the @types packages to their dependency.

Copy link
Collaborator

@donmccurdy donmccurdy Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to play it very safe on this one, I think the approach would be...

dependencies:

  • "@types/react": ">=18.2.0"

peerDependencies:

  • "react": ">=18.2.0"

devDependencies:

  • "@types/react": "^18.2.0"
  • "react": "^18.2.0"

That said, your observation that anyone using TS+React would have these installed already makes sense, and I'm probably overcomplicating it. No objections to your change!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted a previous change so the peer dependency version is now "react": ">=16.3.0 (earliest version of the hooks API). Assume we add "@types/react": ">=16.3.0" to dependencies and a React 16 application imports it:

"dependencies": {
  "@types/react": "^16.9.0",
  "react": "^16.9.0",
  "deck.gl": "^9.0.0"
}

depending on the package manager and order of operation, they may end up with something like:

├─ react@16.9.0
├─ @types/react@16.9.0
├─ @deck.gl/react@9.0.0
│  └─ @types/react@18.2.0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to prevent that, let's go with your approach. 👍🏻

@Pessimistress Pessimistress merged commit c83b87b into master Mar 13, 2024
3 checks passed
@Pessimistress Pessimistress deleted the x/deps branch March 13, 2024 22:30
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.

4 participants