strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

Not working with compiled TypeScript declarations? #18

Closed teddybradford closed 5 years ago

teddybradford commented 6 years ago

I'm trying to use this loader with a Node package that contains both .js files compiled from TypeScript and .d.ts declaration file counterparts. However, it appears that this loader might not be reading the declaration files to generate a proper docgen, and therefore isn't getting component names or proptypes. In Storybook, I'm seeing the following:

image

Does this loader support compiled TypeScript with declarations? If not, is there any workaround for this?

teddybradford commented 6 years ago

Possibly related to #25

teddybradford commented 5 years ago

Closing this, as I believe the solution documented in the following thread solves this same issue: https://github.com/strothj/react-docgen-typescript-loader/issues/25#issuecomment-424136625

usagi-f commented 5 years ago

I have this problem.

For module made by me, did not work by below code.

// .storybook/webpack.config.js
const compilerOptions = {
  ...require('../../../tsconfig.json').compilerOptions,
};

delete compilerOptions.moduleResolution;

module.exports = (baseConfig, env, config) => {
  config.module.rules.push({
    test: /\.(ts|tsx)$/,
    use: [
      {
        loader: require.resolve('babel-loader'),
        options: {
          presets: [['react-app', { flow: false, typescript: true }]],
        },
      },
      {
        loader: require.resolve('react-docgen-typescript-loader'),
        options: { compilerOptions },
      },
    ],
  });
  config.resolve.extensions.push('.ts', '.tsx');
  return config;
};
// *.stories.tsx
import React from 'react';
import { storiesOf } from '@storybook/react';
import { Component } from 'original-modules';
storiesOf('Component', module).add('any caption', () => <Component />)

The exported component by modules has props information what only specific value for example defaultProps. Because already build to not TypeScript.

For the reason, I am hoping to refer by *.d.ts but it rendered only defaultProps.

@teddybradford Did you resolve this issue? How about the implement way?