Hi All, how can I define a top-level typealias tha...
# announcements
l
Hi All, how can I define a top-level typealias that can be used by other classes and functions from various packages? For instance I want
typealias Dict<V> = Map<String, V>
to be made available to other classes
s
liminal: Just declare it at top level in any
.kt
file
l
So I cannot re-use this typealias definition in my project? Ideally it would be defined in one place and used whenever I need to use it within my project.
s
com/test/SomeFile.kt
Copy code
typealias Dict<V> = Map<String, V> // this line can be in any file

data class ClassA(val d: Dict<String>)
com/test/subpackage/SomeOtherFile.kt
Copy code
import com.test.Dict

data class ClassB(val d: Dict<String>)
💯 1
so ofcourse you can re-use it
l
great. i had wrong syntax trying to import it before. thanks!
s
don't code in Notepad 😄 code in IntelliJ
👍 2
it would just import it for you