Could not find a declaration file for module '@material-ui/styles/withStyles'.
See original GitHub issueImporting withStyles from @material-ui/styles/withStyles
is returning a typescript error.
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
No typescript error
Current Behavior 😯
Could not find a declaration file for module '@material-ui/styles/withStyles'. '/Users/vlanglet/Project/cloud/front/node_modules/@material-ui/styles/withStyles.js' implicitly has an 'any' type.
Try `npm install @types/material-ui__styles` if it exists or add a new declaration (.d.ts) file containing `declare module '@material-ui/styles/withStyles';`
5 import withStyles, { StyleRules, WithStyles } from '@material-ui/styles/withStyles';
Steps to Reproduce 🕹
import withStyles, { StyleRules, WithStyles } from '@material-ui/styles/withStyles';
Context 🔦
The following lines return no error but I was expected to import everything from @material-ui/styles/withStyles
import { withStyles } from '@material-ui/styles';
import { StyleRules, WithStyles } from '@material-ui/styles/withStyles';
I assume it’s the same problem for others modules.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.9.1 |
TypeScript | v3.2.2 |
Issue Analytics
- State:
- Created 5 years ago
- Comments:24 (23 by maintainers)
Top Results From Across the Web
Could not find a declaration file for module 'module-name ...
Here are two other solutions. When a module is not yours - try to install types from @types : npm install -D @types/module-name....
Read more >How to fix error TS7016: Could not find a declaration file for ...
Try `npm install @types/XYZ` if it exists or add a new declaration (.d.ts) file containing `declare module 'XYZ';. If XYZ is a direct...
Read more >Fixing the TS7016 Error | Atomist Blog
Could not find declaration file -- How do you get past the TS7016? This article highlights the eight best and worst fixes.
Read more >Could not find a declaration file for module #66 - GitHub
Bug report I am importing a specific file from a library on npm, e.g. import file1 from 'someLib/src/file1'. To get its types to...
Read more >Error: Could not find a declaration file for module - YouTube
Fix error: Could not find a declaration file for module ... implicitly has an 'any' type.Try npm install library-name if it exists or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I understand what’s happening now. We’re declaring the
@material-ui/styles/withStyles
module in@material-ui/styles/index.d.ts
. But if you only ever import from@material-ui/styles/*
typescript never touches theindex.d.ts
where the modules are declared.In a perfect world typescript would fallback to
index.d.ts
but I understand that this is very opinionated about how typescript acquires types. This is also potentially an issue for us if we ever want to flatten the module declarations in@material-ui/core
.I would recommend you use named imports from the index. If you’re concerned with bundle size then you should fix this in your bundler.
@material-ui/styles
is “tree-shake-viable”.If this is not possible you force typescript to read the index.d.ts by simply importing a type e.g.
import { WithStyles } from "@material-ui/styles";
This will never affect your bundle size.I tried adding
node_modules/@material-ui/styles
to thetypeRoots
but then typescript complains because the nestednode_modules
contains no type declarations.Personally I wouldn’t use path imports and just use named imports. Especially since it prevents you from using private members such as
StylesRules
@VincentLanglet Could you try adding
"types": ["@material-ui/styles"]
tocompilerOptions
in your tsconfig? This solved this issue for me. It might however hurt with other type aquisitions.