apple / apple/pkl

Type nested objects.

Open
#352 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

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 (https://github.com/apple/pkl/issues/331#issuecomment-2005233277) 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

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the documentation on object typing and the anonymous-class discussion in issue #331, then compare the requested inline nested syntax with the existing class and module approach. Done means clarifying whether anonymous nested types are planned or identifying the supported alternative and its expected syntax.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.