Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

import React from 'react' doesn't work #62

Open
TheKnarf opened this issue Sep 19, 2019 · 4 comments
Open

import React from 'react' doesn't work #62

TheKnarf opened this issue Sep 19, 2019 · 4 comments

Comments

@TheKnarf
Copy link

TheKnarf commented Sep 19, 2019

Changing the following:

-import * as React from 'react';
+import React from 'react';

Seems to break react-docgen-typescript-loader's ability to generate docgen for components in the file.

@wollardj
Copy link

Example of this is

interface IProps {
  onChange: (event: React.ChangeEvent<HTMLInputElement>);
}

... this will render as (event: any) => void) with import React from 'react', but renders properly with import * as React from 'react'

@TheKnarf
Copy link
Author

TheKnarf commented Sep 26, 2019

Normally Typescript disallows import React from 'react', however you can activate it in tsconfig.json by setting the following:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
  }
}

I assume that this project simply haven't set that option and it therefor fails for every project who have set it too true.

edit It seems to be set for this project, so then I'm unsure what it is.

@dizel3d
Copy link

dizel3d commented Sep 27, 2019

Specify path to your tsconfig.json in tsconfigPath.

{
  loader: require.resolve('react-docgen-typescript-loader'),
  options: {
    tsconfigPath: path.resolve(__dirname, '../tsconfig.json')
  }
},

@wollardj
Copy link

@dizel3d - Thanks! That did the trick! I thought I'd specified that, but it turns out I'd only specified it for ts-loader and forgot to add it to react-docgen-typescript-loader.

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

No branches or pull requests

3 participants