Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback to any / unknown in case of errors in generating .d.ts #2

Closed
vvscode opened this issue Jun 24, 2019 · 7 comments · Fixed by #3
Closed

Add fallback to any / unknown in case of errors in generating .d.ts #2

vvscode opened this issue Jun 24, 2019 · 7 comments · Fixed by #3

Comments

@vvscode
Copy link
Contributor

vvscode commented Jun 24, 2019

@KuveytTurk

In some cases, the generator fails with errors. Looks like it worth to add a fallback to any type in such cases

@vvscode vvscode changed the title Add fallback to any in case of errors in generating .d.ts Add fallback to any / unknown in case of errors in generating .d.ts Jun 26, 2019
@vvscode
Copy link
Contributor Author

vvscode commented Jun 26, 2019

@mozkarakoc will you adopt such MR?

@mozkarakoc
Copy link
Contributor

mozkarakoc commented Jun 26, 2019

The generator returns any propType for undefined props. Could you provide more detailed sample input and expected output?

@vvscode
Copy link
Contributor Author

vvscode commented Jun 26, 2019

./Feedback.js
https://gist.github.com/vvscode/be98fb5072b498172913e3703edb7e16

const { generate }  = require('react-dts-generator');
const result = generate({
  input: './Feedback.js',
	isBaseClass: true,
});

console.log(result);

gives me

~/r/docgen-issue [1]> node index.js
/Users/vvscode/repo/docgen-issue/node_modules/react-dts-generator/bin/src/utils.js:67
        values.forEach(item => unions += `${item.value} | `);
               ^

TypeError: values.forEach is not a function
    at generateOneOf (/Users/vvscode/repo/docgen-issue/node_modules/react-dts-generator/bin/src/utils.js:67:16)
    at Object.generateProp (/Users/vvscode/repo/docgen-issue/node_modules/react-dts-generator/bin/src/utils.js:137:29)
    at /Users/vvscode/repo/docgen-issue/node_modules/react-dts-generator/bin/src/index.js:44:46
    at Array.forEach (<anonymous>)
    at generate (/Users/vvscode/repo/docgen-issue/node_modules/react-dts-generator/bin/src/index.js:39:22)
    at Object.<anonymous> (/Users/vvscode/repo/docgen-issue/index.js:2:16)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)

debug output in code

    function generateOneOf(name, values, flag) {
        let unions = '';
        values.forEach(item => unions += `${item.value} | `);
        unions = unions.substr(0, unions.length - 3);
        const property = dom.create.property(name, unions, flag);
        return { property };
    }

gives me

generateOneOf { name: 'feedbackActiveStep', values: 'Object.values(STEP)', flag: 8 }

@vvscode
Copy link
Contributor Author

vvscode commented Jun 26, 2019

I'm ready to provide a PR with tests and so on. Just wondering if you're fine about it

@mozkarakoc
Copy link
Contributor

mozkarakoc commented Jun 26, 2019

I think this is a bug and it would be nice to fix. PR's are always welcome.

@vvscode
Copy link
Contributor Author

vvscode commented Jun 26, 2019

#2

@mozkarakoc
Copy link
Contributor

@vvscode thanks for your contribution. I'll publish a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants