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

Make deepToTyped redundant by improving toTyped #769

Open
holzensp opened this issue Nov 1, 2024 · 0 comments
Open

Make deepToTyped redundant by improving toTyped #769

holzensp opened this issue Nov 1, 2024 · 0 comments

Comments

@holzensp
Copy link
Contributor

holzensp commented Nov 1, 2024

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.

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

1 participant