apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
9.84k stars 259 forks source link

Implement nested types #563

Open HT154 opened 2 days ago

HT154 commented 2 days ago

I'd like to be able to do something like this:

class MyA {
  properties: Properties

  class Properties {
    prop1: String
  }
}

class MyB {
  properties: Properties

  class Properties {
    prop2: String
  }
}

aProps: MyA.Properties

Currently, this requires disambiguating classes with only naming, which can lead to very long class names with more deeply nested structures. This code today must look like this:

class MyA {
  properties: MyAProperties
}

class MyAProperties {
  prop1: String
}

class MyB {
  properties: MyBProperties
}

class MyBProperties {
  prop2: String
}

aProps: MyAProperties
bioball commented 1 day ago

I'm kind of bearish on this idea--this feature is a request to use classes as namespaces, and I don't know if that is a suitable use of classes.

Today, I'd suggest doing what you're doing (disambiguate the plain class name), or, alternatively, put them in different modules.