Why can't I use @PublishedApi for typealias?

In my current project I have a public interface for different requests

interface Query<T>

      

and an internal implementation for this interface. Since I have built-in functions for making different requests, I need to use @PublishedApi

for this class

@PublishedApi
internal class QueryImpl<T> : Query<T>

      

Now, for convenience, I want to define some type aliases for different types of queries.

typealias MatchQuery = Query<MatchQueryProperties>

      

this works very well for this public interface, but I need to create one instance of it in my public inline function

inline fun match(init: MatchQuery.() -> Unit) {
    // It would look nicer if I could use MatchQueryImpl().init()
    QueryImpl<MatchQueryProperties>().init()
}

      

But instead of writing QueryImpl<PropertiesType>

for each request type, I want to use internal types for implementation too.

// fails because it needs to be internal
typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>

// can't be used in public inline functions
internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties> 

// annotation can't be used on typealias
@PublishedApi internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>

      

So my questions are:
Can I use it in some way @PublishedApi internal typealias

?
If not, why can't I use it?
Is there another way to archive what I want?

+3


source to share


1 answer


You cannot currently use non-public post types in the publicly built-in function. This is a current flaw in how a built-in function checks if it's ok to use a non-public API inside its body.



I opened issue KT-19407 to track and discuss this issue.

+1


source







All Articles