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

unused-fields rule don't respect typescript's typeof value #148

Open
roman-antl-satoshilabs opened this issue Dec 27, 2023 · 0 comments
Open

Comments

@roman-antl-satoshilabs
Copy link

roman-antl-satoshilabs commented Dec 27, 2023

Hello,

I have the following typescript code:

export const supportedCurrenciesEnum = ['usd', 'eur', 'czk'] as const;
export type supportedCurrencyType = (typeof supportedCurrenciesEnum)[number];

// then in the fragment query i'm using this code:

fragment {
  salePercentage {
            czk
            usd
            eur
        }
} 

// then deep in the react code i'm trying to access the salePercentage value like this:
const currencyCode: supportedCurrencyType = 'czk';

salePercentage[currencyCode]

But the rule still complaining on the fields in the fragment:

This queries for the field `czk` but this file does not seem to use it directly. If a different file needs this information that file should export a fragment and colocate the query for the data with the usage.
If only interested in the existence of a record, __typename can be used without this warning.eslint(relay/unused-fields)

But when i access the salePercentage like this:

const value = currencyCode === 'czk' ? salePercentage.czk : currencyCode === 'eur' ? salePercentage.eur : salePercentage.usd;

It works.

Do you have please any idea how to keep the easy access and don't use the second approach without the eslint warning?

Thank you

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

No branches or pull requests

1 participant