Skip to content

How to declare global variable for ESLint #233

@ospfranco

Description

@ospfranco

Hi, I'm creating a JSI module and I have registered the module on the global object, here is my index.ts:

export type CoinType = 'ethereum';

declare const WalletCore: {
  createWallet: (
    strength: 128 | 256,
    passphrase?: string
  ) => { mnemonic: string; seed: string };
  importWalletFromMnemonic: (
    seed: string,
    passphrase?: string
  ) => { mnemonic: string; seed: string };
  importWalletFromHexString: (
    hex: string,
    passphrase?: string
  ) => { mnemonic: string; seed: string };
  getAddressForCoin: (coinName: CoinType) => string;
  deriveAddressForCoin: (coinType: CoinType, derivationPath: string) => any;
};

You can see I simply declare a global variable, which works just fine for type checking, the problem comes on the example project, ESLint complains the variable has not been declared anywhere.

Screenshot 000078

I have also declared the variable in the root package.json

"eslintConfig": {
    "root": true,
    "globals": {
      "WalletCore": true
    },

What's the correct way to add a global variable to ESLint so that when the library is a dependency ESLint knows about the global variable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions