swap-ui icon indicating copy to clipboard operation
swap-ui copied to clipboard

Type mismatch with `sol-wallet-adapter` and `anchor/dist/provider`.

Open lieuzhenghong opened this issue 3 years ago • 3 comments

Not sure where to put this, but trying to build the example page with sol-wallet-adapter 0.2.5 and anchor 0.11.1 gives a type mismatch.

Argument of type 'import("..../node_modules/@project-serum/sol-wallet-adapter/dist/cjs/index").default' is not assignable to parameter of type 'import(".../node_modules/@project-serum/anchor/dist/provider").Wallet'.
  Types of property 'publicKey' are incompatible.
    Type 'PublicKey | null' is not assignable to type 'PublicKey'.
      Type 'null' is not assignable to type 'PublicKey'.  TS2345

    139 |     onTransaction: (tx: TransactionSignature | undefined, err?: Error) => void
    140 |   ) {
  > 141 |     super(connection, wallet, opts);
        |                       ^
    142 |     this.onTransaction = onTransaction;
    143 |   }
    144 |

I believe this migration to Typescript in sol-wallet-adapter was the one that broke it: here.

We can see the export interface Wallet in anchor/ts/provider.ts still uses PublicKey instead of PublicKey | null here.

lieuzhenghong avatar Jul 20 '21 09:07 lieuzhenghong

Not sure where to put this, but trying to build the example page with sol-wallet-adapter 0.2.5 and anchor 0.11.1 gives a type mismatch.

Argument of type 'import("..../node_modules/@project-serum/sol-wallet-adapter/dist/cjs/index").default' is not assignable to parameter of type 'import(".../node_modules/@project-serum/anchor/dist/provider").Wallet'.
  Types of property 'publicKey' are incompatible.
    Type 'PublicKey | null' is not assignable to type 'PublicKey'.
      Type 'null' is not assignable to type 'PublicKey'.  TS2345

    139 |     onTransaction: (tx: TransactionSignature | undefined, err?: Error) => void
    140 |   ) {
  > 141 |     super(connection, wallet, opts);
        |                       ^
    142 |     this.onTransaction = onTransaction;
    143 |   }
    144 |

I believe this migration to Typescript in sol-wallet-adapter was the one that broke it: here.

We can see the export interface Wallet in anchor/ts/provider.ts still uses PublicKey instead of PublicKey | null here.

As a workaround, you can use // @ts-ignore.

armaniferrante avatar Jul 20 '21 18:07 armaniferrante

I am Facing the same issue here, any working solutions ?

thevenice avatar Aug 30 '21 09:08 thevenice

I have the same issue here as well I fixed it by doing:

    const { publicKey, wallet, signTransaction, signAllTransactions } = useWallet();
    if (!wallet || !publicKey || !signTransaction || !signAllTransactions) {
      return;
    }
    const signerWallet = {
      publicKey: publicKey,
      signTransaction: signTransaction,
      signAllTransactions: signAllTransactions,
    };

    const provider = new Provider(connection, signerWallet, {
      preflightCommitment: "recent",
    });

TheXienator avatar Feb 15 '22 18:02 TheXienator