Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type nested objects. #352

Open
tmerse opened this issue Mar 21, 2024 · 1 comment
Open

Type nested objects. #352

tmerse opened this issue Mar 21, 2024 · 1 comment

Comments

@tmerse
Copy link

tmerse commented Mar 21, 2024

Trying to type nested objects seems unnecessarily verbose.
According to the documentation, typing objects is possible via classes or modules.

In order to type an object with nested properties, at least two class declarations are needed.

foo: Foo = new {
  bar = 23
  nested {
    baz = "nested_object_properrty"
  }
}

class Foo {
  bar: Number
  nested: Nested
}

class Nested {
  baz: String
}

Compared to e.g. TypeScript interfaces or types and other constructs to define types inline this seems a little verbose.

Sth. like anonymous classes (#331 (comment)) seem more suitable for some of such cases considering one of pkl's stated advantages (https://pkl-lang.org/main/current/introduction/comparison.html#general-purpose-langs)

Pkl code often resembles the configuration it generates.

class Foo {
  bar: Number
  nested: class {
    baz: String
  }
}

Is something like this planned or are there other means to achieve this?

Thank you

@bioball
Copy link
Contributor

bioball commented Mar 22, 2024

We don't have any particular plans, but it's admittedly a pain point.

One possible solution is anonymous classes, like I mentioned in that comment. We're also thinking about whether we'd want to introduce structural types, which might provide another solution for pain points like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants