Skip to content

Make deepToTyped redundant by improving toTyped #769

Open
@holzensp

Description

Currently, toTyped is shallow. For example, given

class Bird {
  name: String
  diet: Listing<String>
}

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<String>
          ^^^^^^^^^^^^^^^
at repl#Bird.diet (repl:pkl0)

This is why deepToTyped was developed. However, toTyped should recursively convert to the required typed structure.

By default this should retain laziness.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions