Skip to content

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

Description

@roman-antl-satoshilabs

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions