Skip to content

Row is possibly undefined #6

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

Closed
woowenjun99 opened this issue Jan 2, 2024 · 2 comments · Fixed by #18
Closed

Row is possibly undefined #6

woowenjun99 opened this issue Jan 2, 2024 · 2 comments · Fixed by #18

Comments

@woowenjun99
Copy link
Contributor

This is not a bug but more of an annoying issue. Upon generating the TypeScript file, there is an issue where row might be undefined during const row = result.rows[0];. One simple solution would be to typecast by editing the generated file, but it is not really ideal. Would there be a better solution to this?

Screenshot 2024-01-03 at 12 39 57 AM Screenshot 2024-01-03 at 12 39 52 AM
@kyleconroy
Copy link
Contributor

We can update the generated code with an additional if statement. Can you edit the code to add the following if statement and see if things are fixed?

    if (result.rows.length !== 1) {
        return null;
    }
    const row = result.rows[0];
    if (!row) {
        return null;
    }
    return {
        id: row[0],
        name: row[1],
        bio: row[2]
    };

@woowenjun99
Copy link
Contributor Author

woowenjun99 commented Jan 3, 2024

Yeap adding in the additional if statement does remove the error. However, it leads to another linting issue of unsafe assignment. I can disable the lint for this.

Screenshot 2024-01-03 at 8 15 21 AM

kyleconroy added a commit that referenced this issue Mar 3, 2024
Fixes a compiler error.
Fixes #6
kyleconroy added a commit that referenced this issue Mar 3, 2024
Fixes a compiler error.
Fixes #6
kyleconroy added a commit that referenced this issue Mar 3, 2024
Fixes a compiler error.
Fixes #6
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