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

[Feature Request] Import deconstruction (& aliasing/macros) #966

Open
joshqou opened this issue Feb 19, 2025 · 1 comment
Open

[Feature Request] Import deconstruction (& aliasing/macros) #966

joshqou opened this issue Feb 19, 2025 · 1 comment

Comments

@joshqou
Copy link

joshqou commented Feb 19, 2025

Deconstruction is a quality of life feature that a lot of languages have nowadays. Since Pkl lacks the ability to alias imported functions and structures, it results in a lot of repetitive ProprietaryServiceConfig.ReusedClassThing or extending a class without adding anything so it can be referenced without explicitly specifying the module. This gets quite messy when different classes result in different output and the end-user file is expected to cast as one or another.

An implementation would essentially let someone do an ES-like deconstructed import like this:

// Provides `convertToHCL` and `Terraform`
import "/path/to/file.pkl" as { convertToHCL, Terraform }
// Provides `Terraform`, and the module as `file`
import "/path/to/file.pkl" as file, { Terraform }

It would also be handy to be able to write aliases or macros within a pkl file, in a similar way to how typealiases currently work. I'm primarily interested in making it easier to repeatedly reference module exports but it could also be useful for other things as well.

import "/path/to/file.pkl"
alias convertToHCL = file.convertToHCL

output {
    value = convertToHCL(someKey)
}
@bioball
Copy link
Contributor

bioball commented Feb 21, 2025

This feature makes sense to me.

Would like some feedback from the community to help us prioritize 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