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

Generating node/file-extension-in-import results in a type error #141

Closed
Shinigami92 opened this issue Oct 4, 2022 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@Shinigami92
Copy link
Collaborator

image

@Shinigami92 Shinigami92 added the bug Something isn't working label Oct 4, 2022
@Julien-R44
Copy link
Collaborator

Okay so this error is caused by https://github.com/bcherny/json-schema-to-typescript generating this invalid type.

The old version you show in the diff was a manual modification

So I guess I don't feel like going to fork json-schema-to-typescript to fix this bug, I think it would be a bit complicated. ( I'll probably look at it in more detail ).

What is on the other hand can be done quite easily, is to implement a patch on our side :
We could just make a small method that analyzes the AST of each rule file. If ever it detects this pattern, then it will automatically correct it by replacing it with an union

@Shinigami92
Copy link
Collaborator Author

@Julien-R44 I already exactly thought about the second proposed strategy: implementing a rule-patcher system where you can register some rules with a patched that will be applied on generating.

@Julien-R44
Copy link
Collaborator

Ahah, perfect, I'll do that then 😋

@Shinigami92
Copy link
Collaborator Author

Ahah, perfect, I'll do that then yum

@Julien-R44 And because I love your reporter and terminal colors 💚 how about showing e.g. in a yellow-ish color how many were patched while generating 🙂

@Dimava
Copy link
Contributor

Dimava commented Apr 1, 2023

This problem also happens in updated @graphql-eslint/naming-convention

I have encountered this problem while doing #177 and chose to just write a replacer

      // fix generated object type having incompatible index signature
      // and narrow it down to starts-with-dot as per documentation
      case 'node/file-extension-in-import': {
        this.content = this.content.replace(
          `
        tryExtensions?: string[];
        [k: string]: 'always' | 'never';`,
          `
        tryExtensions?: string[];
        [ext: \`.\${string}\`]: 'always' | 'never';`,
        );
        break;
      }

@Shinigami92
Copy link
Collaborator Author

This was fixed by #180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants