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
Hello,
I have the following typescript code:
But the rule still complaining on the fields in the fragment:
But when i access the salePercentage like this:
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