-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
modules/react/package.json
Outdated
"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" | ||
}, |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 👍🏻
Non-TypeScript users should not be forced to install types
Change List
@types/react
and@types/react-dom
to devDependencies