Docz: Can I modify `propFilter`?

Created on 18 Sep 2018  路  4Comments  路  Source: doczjs/docz

Question

Hi, is there a way I can modify docgen-typescript's propsFilter?

Description
I have the same exact issue as https://github.com/styleguidist/react-docgen-typescript/pull/111 were my PropsTable is populated with all the html props/attrs which makes it a bit hard to use. I was wondering if there is a way I can pass the same function as he is using:

propFilter: (prop) => {
      if (prop.parent == null) {
        return true;
      }

      return prop.parent.fileName.indexOf('node_modules/@types/react') < 0;
    }

Seems like thats all I should need

docz-core feature request

Most helpful comment

For everyone coming to this issue, I think I finally found out what is going on here. For the use case of this issue, we don't really need the custom propFilter, since docz already ignores properties coming from node_modules. However, they were still not filtered out for me.

The issue was, that docz' propFilter still always received a prop with parent being undefined. react-docgen-typescript will only set the prop.parent (see snippet of previous comment), if the encountered parent kind is either InterfaceDeclaration or TypeAliasDeclaration. As you can see here, those are mapped by numbers. Now, those numbers seem to change between typescript versions and while my app was using typescript 3.7, docz-core uses 3.5, this lead to a configuration where my parent interfaces (e.g. React.HTMLAttributes) had the kind 242, which was then mapped to VariableDeclarationList, which is obviously neither InterfaceDeclaration nor TypeAliasDeclaration.

I was able to fix this issue for me by forcing one typescript version via (inside my package.json):

  "resolutions": {
    "typescript": "3.7.3"
  },

All 4 comments

Unfortunately, right now we're very restricted about the react-docgen configuration because the babel-plugin-react-docgen and the loader, but we're working to improve this 馃檹

Any updates on this?

It looks like we can provide a propFilter inside our doczrc.js config (https://github.com/pedronauck/docz/blob/c0749d32d9b806b8a83fb91f0dbb34203585df4f/core/docz-core/src/config/argv.ts#L97). E.g.

docgenConfig: {
    propFilter: (prop) => {
      if (!prop.parent) {
        return true;
      }

      return prop.parent.fileName.indexOf('node_modules/@types/react') < 0;
    }
  }

However, it looks like prop.parent is always undefined, even for properties coming from extends React.HTMLAttributes<HTMLButtonElement>. So this approach doesn't seem to work for docz.

For everyone coming to this issue, I think I finally found out what is going on here. For the use case of this issue, we don't really need the custom propFilter, since docz already ignores properties coming from node_modules. However, they were still not filtered out for me.

The issue was, that docz' propFilter still always received a prop with parent being undefined. react-docgen-typescript will only set the prop.parent (see snippet of previous comment), if the encountered parent kind is either InterfaceDeclaration or TypeAliasDeclaration. As you can see here, those are mapped by numbers. Now, those numbers seem to change between typescript versions and while my app was using typescript 3.7, docz-core uses 3.5, this lead to a configuration where my parent interfaces (e.g. React.HTMLAttributes) had the kind 242, which was then mapped to VariableDeclarationList, which is obviously neither InterfaceDeclaration nor TypeAliasDeclaration.

I was able to fix this issue for me by forcing one typescript version via (inside my package.json):

  "resolutions": {
    "typescript": "3.7.3"
  },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

xingBri picture xingBri  路  29Comments

ronghang picture ronghang  路  33Comments

pedronauck picture pedronauck  路  68Comments

maxguzenski picture maxguzenski  路  24Comments

lorenzorapetti picture lorenzorapetti  路  31Comments