-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Refine how TypeScript types are handled #5593
Conversation
@weswigham I think you brought this up when we discussed the changes PR earlier. I feel like a global |
By global p.s. thanks for the quick response! |
Yeah, I mentioned you could publish the file to |
I'm worried about versioning and keeping them in sync, would we be able to conceal the dependency from the user by making |
You could list it as a... Peer dependency, I think? So npm will warn if the versions in their project and what the scripts think is right don't match sufficiently. |
Since TypeScript is optional we'd need to wait for the optional peer dependencies specification to be finalized between Yarn and npm 😅. Maybe copying the file is the best behavior for now... |
Note: I don't want to go against TypeScript community convention, but I'm not sure if Because of the above constraint, I feel like it might be best to be consistent and copy the file so there's a better eject story. I'm more than open to an alternate way to do this than copying a type declaration file into the user's directory. For the meantime, I've altered this PR to restore the copy behavior with additions of type references. |
You could try making |
Wow, that's actually an excellent idea! 🤯 Thanks for the suggestion, I think that'll probably work best. |
Yes this should work @Timer. As we were chatting earlier, this would be picked up automatically by TypeScript (as well as i was mentioning VSCode should pick this up for javascript projects as well in my experience). Are you mainly concerned with |
What's best practice to specify our type dependencies (
|
Also, is this best practice since we need the types to be installed?
Yes, that's my concern. e.g. |
IMO:
Another thought if you didn't want to manage an |
|
react-scripts
I think since |
For a while until Yarn PnP is more widespread. Can you DM me on Twitter @timer150? |
We decided to not publish a types package, but instead use a derivative of the suggested env package. Please review this PR and let me know if this seems reasonable! I'm going to merge for now because it's an improvement. |
* Specify types in package * Do not remove types file on eject * Stop copying types into generated project * Reference react and react-dom * Reference node types * Install node types as well * Restore copying * Add Node to the list of installed types * Reference Jest types * Remove jest types from install * Remove jest from CRA install * Remove Jest reference and let user do this themselves * Stop copying types file * Add types key to package.json * Add appTypeDeclarations and create when missing * Rename declarations file * Add Jest back to install instructions * Minimize diff
* Specify types in package * Do not remove types file on eject * Stop copying types into generated project * Reference react and react-dom * Reference node types * Install node types as well * Restore copying * Add Node to the list of installed types * Reference Jest types * Remove jest types from install * Remove jest from CRA install * Remove Jest reference and let user do this themselves * Stop copying types file * Add types key to package.json * Add appTypeDeclarations and create when missing * Rename declarations file * Add Jest back to install instructions * Minimize diff
Right now, we copy our
react-app.d.ts
file into the user's source folder to register types for our webpack loaders, e.g.:I feel like this isn't very optimal, and I'd rather this be "encapsulated" somehow.
On first thought, it looks like we could publish
@types/react-scripts
and have the types automatically registered -- however, I'm not sure we want that maintenance overhead when thetypes
field exists inpackage.json
.This pull request is exploring how we could rely on the
types
key so our types are always specific to thereact-scripts
version without relying on package manager hoisting metrics/external packages.It looks like we can trigger TypeScript to import these types by specifiying
"types": ["react-scripts"]
intsconfig.json
, but this turns off the default behavior of absorbing the@types/
folder.Also, using
include
intsconfig.json
seems suboptimal because we can't specifynode_modules/react-scripts/config/react-app.d.ts
since it might be hoisted.I suppose the crux of the problem is there's never a time where someone would write
import 'react-scripts';
.