GithubHelp home page GithubHelp logo

Comments (4)

strothj avatar strothj commented on June 12, 2024 1

Sorry for the long delay.

The following change in your Storybook configuration should allow this to work. From my testing it seems to work fine:

  const compilerOptions = {
    ...require("../tsconfig.json").compilerOptions,
    // For allowSyntheticDefaultImports/esModuleInterop, a target of "es6" or
    // above is required. ts-loader will load the project tsconfig.json normally
    // with its compilation settings.
    target: "esnext",
  };
  // If you have the compiler option "moduleResolution", delete it. You'll get
  // an error otherwise.
  delete compilerOptions.moduleResolution;

  config.module.rules.push({
    test: /\.tsx?$/,
    include: path.resolve(__dirname, "../src"),
    use: [
      require.resolve("ts-loader"),
      {
        loader: require.resolve("react-docgen-typescript-loader"),
        // Pass along our customized compiler options to enable synthetic
        // default imports.
        options: { compilerOptions },
      },
    ],
  });

The base package react-docgen-typescript has a default config that it uses when no options are supplied:

const defaultOptions: ts.CompilerOptions = {
  jsx: ts.JsxEmit.React,
  module: ts.ModuleKind.CommonJS,
  target: ts.ScriptTarget.Latest
};

You might be able to just use the loader option: tsconfigPath. I haven't tested it yet.

from react-docgen-typescript-loader.

strothj avatar strothj commented on June 12, 2024

Can you please provide the source for the Storybook story? Thank you.

from react-docgen-typescript-loader.

teddybradford avatar teddybradford commented on June 12, 2024

@strothj Sure thing! Here's the story for the Heading component:

import { select, text, withKnobs } from "@storybook/addon-knobs";
import { storiesOf } from "@storybook/react";
import React from "react";
import { Heading } from "../../src/components/heading";

const stories = storiesOf("Components|Text", module);
stories.addDecorator(withKnobs);

stories.add("Heading", () => (
  <Heading level={select("level", ["1", "2", "3"], "1")}>
    {text("text", "My heading")}
  </Heading>
));

from react-docgen-typescript-loader.

teddybradford avatar teddybradford commented on June 12, 2024

@strothj Thank you! I can confirm that this was the issue with my setup. The default compilerOptions were conflicting with the settings in my tsconfig.json file. Aligning the loader config with tsconfig.json fixed the issue. 🙂

from react-docgen-typescript-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.