-
Notifications
You must be signed in to change notification settings - Fork 801
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
It references "react" in the public typing declarations but doesn't add a dependency for "@types/react" #1359
It references "react" in the public typing declarations but doesn't add a dependency for "@types/react" #1359
Comments
That's bad. That means that I have to change peer dependencies for all 100500 packages I've ever created. Is there any |
@slavafomin Can you please provide the steps to reproduce? |
@theajr I can't give you a detailed example, but the gist of it is that you need to create a TypeScript React application using |
You only need to specify |
For those, who are using Rush the following workaround could be used to mitigate the situation until it's fixed in this package: // common/config/rush/pnpmfile.js
'use strict';
const rewriteRules = {
// @todo: remove this rule when the issue is fixed
// @url https://github.com/gaearon/react-hot-loader/issues/1359
'react-hot-loader': {
setDependencies: {
'@types/react': '>=16',
},
},
};
// https://rushjs.io/pages/configs/pnpmfile_js/
module.exports = {
hooks: {
readPackage: rewriteManifest,
},
};
function rewriteManifest(manifest, context) {
normalizeManifest(manifest);
const { name, dependencies } = manifest;
const rule = rewriteRules[name];
if (rule) {
Object.assign(dependencies, rule.setDependencies);
context.log(`Rewritten package "${name}" dependencies`);
}
return manifest;
}
function normalizeManifest(manifest) {
if (!manifest.dependencies) {
manifest.dependencies = {};
}
} Feel free to add other dependencies in the |
Fixed in |
@slavafomin - would it work if |
@theKashey yes, I would recommend to add it as a peer dependency. |
It should be added both as a |
4.12.17 released with a fix |
Works! |
Hello!
Thank you for this great plugin!
However, in published
index.d.ts
file you are referencing thereact
package in some exports of yours. However, you don't specify the dependency for@types/react
, which causes issues in projects where TypeScript compiler is running in "strict" mode and where dependencies are installed by a more strict package manager likepnpm
(Rush).It gives the following TypeScript error during application compilation:
As you have
react
in your peer dependencies, you should also add@types/react
there as well in order for TypeScript projects to be able to resolve typing declarations correctly.Thanks!
The text was updated successfully, but these errors were encountered: