react-docgen-typescript-loader icon indicating copy to clipboard operation
react-docgen-typescript-loader copied to clipboard

import React from 'react' doesn't work

Open TheKnarf opened this issue 5 years ago • 4 comments

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.

TheKnarf avatar Sep 19 '19 13:09 TheKnarf

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'

wollardj avatar Sep 26 '19 01:09 wollardj

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.

TheKnarf avatar Sep 26 '19 07:09 TheKnarf

Specify path to your tsconfig.json in tsconfigPath.

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

dizel3d avatar Sep 27 '19 06:09 dizel3d

@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.

wollardj avatar Sep 30 '19 00:09 wollardj