thirdweb-dev/js

Thirdweb overrides the viem Address type

Closed this issue · 2 comments

If importing the thirdweb library, the address type of viem (aka 0x${string}) is replaced with a simple string.

This is a problem for codebase strongly typed as this breaks some types validation and can end up breaking the build.

I believe this is related to this file:

AddressType: string;

Is there a good reason to do that? Is there any good workaround for it?

Way to reproduce:

  • npm init
  • npm i viem typescript thirdweb

Create a file index.ts with the following.

// import {} from "thirdweb";
import { getAddress } from "viem";

function test(address: `0x${string}`) {
  console.log(address);
}

const address = getAddress("0x123");
test(address);

This way, the build works, but if you uncomment import {} from "thirdweb" the build doesn't work anymore

One workaround possible is to reimplement properly in a global.d.ts file the following

declare module "abitype" {
  export interface Register {
    AddressType: `0x${string}`;
  }
}

Hey @antho1404, this is an intentional override we place on abitype, which viem also happens to use. You're welcome to override the type yourself as you described, but it would be a breaking change on our end to change this.