safe-core-sdk icon indicating copy to clipboard operation
safe-core-sdk copied to clipboard

Type Safety Issue: Global Module Augmentation Weakens Address Types

Open pheuberger opened this issue 11 months ago • 1 comments

Description

Installing @safe-global/api-kit changes the global type definition for Ethereum addresses from 0x${string} to string through a module augmentation of abitype:

// In @safe-global/api-kit/dist/index.d.ts
declare module 'abitype' {
  interface Register {
    AddressType: string;
  }
}

This global change affects all packages that depend on abitype for their types (including viem and by extension wagmi), weakening type safety across the entire consuming application.

Impact

  1. Changes viem's Address type from 0x${string} to string project-wide
  2. Affects type safety in consuming applications that rely on strict address typing
  3. Makes it harder to catch malformed addresses at compile time
  4. Prevents applications from maintaining stricter address types even in their own code

Attempted Solutions

  1. Creating a local module augmentation to restore the stricter type results in TypeScript resolving the type to any
  2. No way to "opt out" of the global type modification

Environment

  • Safe Core SDK versions:
    • api-kit: 2.5.4
  • viem: 2.21.55
  • TypeScript: 5.7.2

Steps to reproduce

  1. Go to https://www.typescriptlang.org/play
  2. First import Address from viem alone and inspect the type
  3. Import API Kit before viem and inspect type again

tsplayground-viem

image

Expected result

Installing @safe-global/api-kit should not affect the type definitions of other packages. The Address type from viem should remain 0x${string} regardless of whether Safe API Kit is installed or not.

pheuberger avatar Dec 20 '24 15:12 pheuberger

I've also found out about 40 new type errors after I've upgraded the Safe{Wallet} SDKs and I had no idea where they are coming from:D

In my code I've overwritten the addressType from abitype Register back to 0x${string} which made the type errros disappear:).

microHoffman avatar May 14 '25 22:05 microHoffman