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

Typescript Import Errors #2978

Closed
mtdewers opened this issue Mar 8, 2019 · 10 comments
Closed

Typescript Import Errors #2978

mtdewers opened this issue Mar 8, 2019 · 10 comments
Labels

Comments

@mtdewers
Copy link

mtdewers commented Mar 8, 2019

What you were expecting:
Expected that a Typescript based react-admin website that had no Typescript compile errors would continue to not have any compile errors when react-admin was updated from version 2.7.2 to 2.7.3.

What happened instead:
An import statement like:
import { Layout } from 'react-admin';

began displaying errors like:

Module '".../web/node_modules/react-admin/esm"' has no exported member 'Layout'.

Other information:
I believe this behavior was introduced in PR #2924 when the following change was made to the react-admin/package.json file:

"declaration": true,

Apparently, since the ra-ui-materialui package is not yet producing types, any types found in that package that are imported in Typescript cause errors.

Environment

  • React-admin version: 2.7.3
  • Last version that did not exhibit the issue (if applicable): 2.7.2
  • React version: 16.3.2
  • Browser: Chrome Version 72.0.3626.121
@djhi
Copy link
Contributor

djhi commented Mar 8, 2019

Thanks, so we need to remove the declarations from the react-admin package until everything is typed...

@mtdewers
Copy link
Author

Just tried version 2.8.0 and this bug still exists. I created a repository that demonstrates the issue. Apparently, since some the *.d.ts files exist the problem remains.

I noticed that #2984 is currently being worked. Is that slated for the next release or will that be a while yet?

@fzaninotto
Copy link
Member

No, #2984 will take weeks. We'll have to hotfix 2.8.0.

@fzaninotto
Copy link
Member

@mtakayuki I tested the #2988 patch in your repository, and there are no more compilation errors. Thanks a lot for taking the time to post the code demonstrating the issue!

@Bnaya
Copy link
Contributor

Bnaya commented Mar 18, 2019

as of 2.8.2 i'm still getting these errors

@fzaninotto
Copy link
Member

Did you wipe out the node_modules and reinstall? I used your repository and couldn't see the errors.

@Bnaya
Copy link
Contributor

Bnaya commented Mar 28, 2019

yes

node_modules/ra-core/esm/util/Query.d.ts:15:32 - error TS7016: Could not find a declaration file for module 'react-redux'. '/Users/bnaya/dev/brandtotal/backoffice-fullstack/node_modules/react-redux/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-redux` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-redux';`

15 declare const _default: import("react-redux").ConnectedComponentClass<any, Pick<{}, never> & RawProps>;
                                  ~~~~~~~~~~~~~

node_modules/ra-core/esm/util/TestContext.d.ts:12:18 - error TS7016: Could not find a declaration file for module 'redux-form'. '/Users/bnaya/dev/brandtotal/backoffice-fullstack/node_modules/redux-form/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/redux-form` if it exists or add a new declaration (.d.ts) file containing `declare module 'redux-form';`

12     form: import("redux-form").FormStateMap;
                    ~~~~~~~~~~~~

node_modules/ra-core/esm/util/withDataProvider.d.ts:48:63 - error TS7016: Could not find a declaration file for module 'react-redux'. '/Users/bnaya/dev/brandtotal/backoffice-fullstack/node_modules/react-redux/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-redux` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-redux';`

48 declare const withDataProvider: <T>(Component: any) => import("react-redux").ConnectedComponentClass<any, Pick<{}, never> & T>;
                                                                 ~~~~~~~~~~~~~

[1:05:19 PM] Found 23 errors. Watching for file changes.

And i'm not sure which repo you referring to,
the errors are on the consuming project

The immediate workaround is "skipLibCheck": true,

But better to fix the lib :)

@fzaninotto fzaninotto reopened this Mar 28, 2019
fzaninotto added a commit that referenced this issue Mar 28, 2019
ghodsizadeh pushed a commit to ghodsizadeh/react-admin that referenced this issue May 21, 2019
ghodsizadeh pushed a commit to ghodsizadeh/react-admin that referenced this issue May 21, 2019
@fzaninotto fzaninotto mentioned this issue Jul 26, 2019
3 tasks
@alexander-alvarez
Copy link

Hi. Should this be set back to true again now that things the different packages are typescript?
https://github.com/marmelab/react-admin/blob/master/packages/react-admin/tsconfig.json#L6

Getting

Could not find a declaration file for module 'react-admin'. '/home/alexalvarez/dev/hasura-poc/react-admin/node_modules/react-admin/lib/index.js' implicitly has an 'any' type.
when doing

import { Admin, Resource, ListGuesser } from 'react-admin';

on v2.9.8

@fzaninotto
Copy link
Member

The react-admin package doesn't export types at the moment. You'll need to add a react-admin.d.ts file with the following content to use it in a Typescript project:

declare module 'react-admin';

@Vadorequest
Copy link

Discussion regarding TS has moved to #1617 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants