safe-core-sdk
safe-core-sdk copied to clipboard
Type Safety Issue: Global Module Augmentation Weakens Address Types
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
- Changes
viem'sAddresstype from0x${string}tostringproject-wide - Affects type safety in consuming applications that rely on strict address typing
- Makes it harder to catch malformed addresses at compile time
- Prevents applications from maintaining stricter address types even in their own code
Attempted Solutions
- Creating a local module augmentation to restore the stricter type results in TypeScript resolving the type to
any - 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
- Go to https://www.typescriptlang.org/play
- First import Address from
viemalone and inspect the type - Import API Kit before
viemand inspect type again
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.
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:).