Skip to content

Default values in Listings/Mappings in combination with Subtypes #651

Answered by HT154
Gr33zy asked this question in Q&A
Discussion options

You must be logged in to vote

This is a limitation of Listing/Mapping defaults and is (as of recently) covered in the language reference here: https://pkl-lang.org/main/current/language-reference/index.html

One approach that works provided that you do not need to override commonProperty in specific Listing elements is to amend in that property afterwards using a member predicate:


amends "FooContainer.pkl"

import "Bar.pkl"
import "Baz.pkl"
import "Foo.pkl"

fooList = new {
  new {
    name = "Foo1"
  }
  new Foo {
    name = "Foo2"
  }
  new Bar {
    name = "Bar"
    barSpecificProperty = 0
  }
  new Baz {
    name = "Bar"
    bazSpecificProperty = false
  }
} {
  [[true]] {
    commonProperty = "common"
  }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Gr33zy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants