TestContainers PostgreSQLContainer with Kotlin unit test: "Not enough information to infer type variable SELF"

This trick also works

private val postgresqlContainer = PostgreSQLContainer<Nothing>().apply {

TestContainers depends on construction of generic type C<Self extends C<SELF>>, but Kotlin don't like that. My workaround was to define my own factory class:

class MyPostgreSQLContainer(imageName: String) : PostgreSQLContainer<MyPostgreSQLContainer>(imageName)

And I can use it like that:

private val postgresqlContainer = MyPostgreSQLContainer("postgres:12-alpine")