Access methods of typealias class in Kotlin Multiplatform library

161 views Asked by At

I have created a kotlin multiplatform library. I have used some typealias in the project. For example:

import io.michaelrocks.libphonenumber.android.Phonenumber.PhoneNumber

actual typealias PhoneNumber = PhoneNumber

I'm trying to test it now in an Android app project. The issue is that I cannot use the methods associated with original PhoneNumber class. When I try to make an object of the typealias PhoneNumber, the compiler gives me an error:

Constructor of inner class PhoneNumber can be called only with receiver of containing class

Attached screenshot.

What could be the issue here and how to solve this?

enter image description here

1

There are 1 answers

0
Claude Brisson On

Instead of doing the import and using an unqualified typealias, you should rather do:

actual typealias PhoneNumber = io.michaelrocks.libphonenumber.android.Phonenumber.PhoneNumber

PhoneNumber is an inner static class, so the error message you receive seems wrong, but we read below that the compiler has been unable to properly resolve the type, so it may be a side effect.