hipstersmoothie/react-docgen-typescript-plugin

Trim is not a function

Opened this issue · 12 comments

Having an issue with Typescript 4.3.2 and line 476 on parser.js

var trimmedText = (tag.text || '').trim();
...
TypeError: (tag.text || "").trim is not a function

I output the console and can see in certain scenarios that instead of getting:

{
  name: string,
  text: string
}

I am getting this kind of structure:

{
  name: 'see',
  text: [
    { text: 'https', kind: 'text' },
    {
      text: '://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute',
      kind: 'text'
    }
  ]
}

I'll try to dig deeper tonight to see if I can find out what is happening and try to create a simplified demo.

Same issue here when trying to use TSDX with storybook.

Is there any workaround?

The fix is to update https://www.npmjs.com/package/react-docgen-typescript to v2.0.0 (published two hours ago). Likely you can set it to the version through npm/yarn. I'll do a quick PR to fix it here as well.

@bebraw - great, thank you!

@leepowelldev It looks like v2.0.0 breaks parsing behavior a tiny bit (defaultValue for a snapshot isn't set now). It seems like there's more work to do for a proper fix but likely going with 2.0.0 would fix the trim issue. I'll try to figure out what's causing the regression.

Yeah I agree that updating the library will probably fix the error.

Another related issue : #43

@bebraw Thanks for handling this!

Eyes on this! thanks!

Could you merge this PR? :)

@ptrhck There's a regression in react-docgen-typescript that has to be solved before the update can be done. Here's more info: styleguidist/react-docgen-typescript#366 .

@bebraw It's not exactly a regression; it's an issue with using react-docgen-typescript version 2 with typescript < 4.3. Version 2 had some jsdoc tag parsing changes that only work against >= 4.3, and its typescript peer dep range has been updated to reflect this.

#43 would fix the tag parsing issue by updating this package's typescript version and peer dep. Unfortunately this would also force everyone using this feature within storybook to upgrade to TS 4.3, which may not be feasible. (TS upgrades can be painful and time-consuming for large projects such as my team's and have to be balanced with other priorities; or sometimes upgrades are outright blocked by bugs which aren't resolved until the next minor version.)