Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Safety Issue: Global Module Augmentation Weakens Address Types #1087

Open
pheuberger opened this issue Dec 20, 2024 · 0 comments
Open

Comments

@pheuberger
Copy link

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 added a commit to pheuberger/hypercerts-app that referenced this issue Dec 24, 2024
This patch adds API Kit which unfortunately overrides viem's Address
type and thus introduces build errors around code that was and still is
fine. Please read this GitHub issue for more details:

safe-global/safe-core-sdk#1087

To get the app to build again I needed to assert address to be of type
`0x${string}` in a few places. We know it's the correct type, it's just
that the TypeScript compiler doesn't, so this is safe to do.
pheuberger added a commit to pheuberger/hypercerts-app that referenced this issue Dec 24, 2024
This patch adds API Kit which unfortunately overrides viem's Address
type and thus introduces build errors around code that was and still is
fine. Please read this GitHub issue for more details:

safe-global/safe-core-sdk#1087

To get the app to build again I needed to assert address to be of type
`0x${string}` in a few places. We know it's the correct type, it's just
that the TypeScript compiler doesn't, so this is safe to do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant