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

Impossible to handle naming collisions #668

Closed
jorgenfar opened this issue Jun 29, 2023 · 2 comments
Closed

Impossible to handle naming collisions #668

jorgenfar opened this issue Jun 29, 2023 · 2 comments

Comments

@jorgenfar
Copy link

jorgenfar commented Jun 29, 2023

Hello, and thanks for your work on this project!

We are facing an issue, which is that there is a name collision between another PhoneNumber type in our project, and the PhoneNumber provided by PhoneNumberKit. For reasons that are not very interesting to go into here, it is not a possible solution to typealias the other PhoneNumber type.

I would like to fix this issue by typealiasing PhoneNumberKit's PhoneNumber, doing something like this:

import PhoneNumberKit

typealias PhoneNumberKitNumber = PhoneNumberKit.PhoneNumber

The reason this is not possible, is that PhoneNumberKit exports a type called PhoneNumberKit, which means that we cannot namespace any imports from PhoneNumberKit; the compiler thinks we are referring to the type, and not the module.

To fix this, I would like to open a PR that renames the PhoneNumberKit type exported --- suggestions for a new name are welcome.

@bguidolim
Copy link
Collaborator

Hey @jorgenfar

Thanks for raising awareness about it.

Because of the lack of a proper name and it would be a breaking change, I still need to think I little bit more about it.
However you can fix it by creating a new file, let's call it PhoneNumberKit+Alias.swift, and adding the following code:

import struct PhoneNumberKit.PhoneNumber
typealias MyPhoneNumber = PhoneNumberKit.PhoneNumber

Or depending on your code, you can import the struct directly into the file you will use.

I hope it helps.

@jorgenfar
Copy link
Author

Hey @jorgenfar

Thanks for raising awareness about it.

Because of the lack of a proper name and it would be a breaking change, I still need to think I little bit more about it. However you can fix it by creating a new file, let's call it PhoneNumberKit+Alias.swift, and adding the following code:

import struct PhoneNumberKit.PhoneNumber
typealias MyPhoneNumber = PhoneNumberKit.PhoneNumber

Or depending on your code, you can import the struct directly into the file you will use.

I hope it helps.

Thank you very much @bguidolim! I wasn't aware it was possible to selectively import like that. That indeed does solve my problem! 😄

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

2 participants