apple / apple/pkl

Make `deepToTyped` redundant by improving `toTyped`

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

Description

Currently, `toTyped` is _shallow_. For example, given
```
class Bird {
name: String
diet: Listing
}

local example: Dynamic = new {
name = "Pigeon"
diet {
"seeds"
"fast food"
}
}

succeeds = example.toTyped(Bird).name
fails = example.toTyped(Bird)
```
would correctly produce
```
succeeds = "Pigeon"
```
if it did not throw on `fails`:
```
–– Pkl Error ––
Expected value of type Listing, but got type Dynamic.
Value: new Dynamic { ?; ? }

3 | diet: Listing
^^^^^^^^^^^^^^^
at repl#Bird.diet (repl:pkl0)
```

This is why [`deepToTyped`](https://pkl-lang.org/package-docs/pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped/current/index.html) was developed. However, `toTyped` _should_ recursively convert to the required typed structure.

By default this should retain laziness.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing `toTyped` behavior and the linked `deepToTyped` documentation, using the nested `Bird` and `Listing` example as the behavioral reference. The change is complete when `toTyped` recursively produces the required typed structure while retaining laziness by default, making `deepToTyped` unnecessary.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
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.