-
Hey, still trying to learn Pkl and ran into a question :) Is there a way to prevent the root of a module file from being used as a type, if the file is defining a few classes but the root has no meaning besides being a package of classes? For example, if I have this abstract class Vehicle {
manufacturer: String
}
class Car extends Vehicle {
transmission: "automatic" | "manual"
}
class Boat extends Vehicle {
has_sails: Boolean
} I want the following to be possible: import "Vehicle.pkl"
vehicles: Collection<Vehicle.Vehicle>
cars: Collection<Vehicle.Car> But not this: import "Vehicle.pkl"
vehicles: Collection<Vehicle> // Has no meaning
cars: Collection<Vehicle.Car> I'm also a bit confused about what the "module" property is intended for, if I add And is there a way to remove the boilerplate of referencing the abstract class with (I'm probably getting a bunch of Pkl concepts mixed up, sorry about that) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi; a module special because it is both an object, and a class. The module is intended to be usable as a type. I would structure your code this way: abstract module Vehicle
import "Vehicle.pkl" // self-import
manufacturer: String
class Car extends Vehicle { // extends the module's class
transmission: "automatic" | "manual"
}
class Boat extends Vehicle {
has_sails: Boolean
} |
Beta Was this translation helpful? Give feedback.
Hi; a module special because it is both an object, and a class. The module is intended to be usable as a type. I would structure your code this way: