Skip to content

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

@joshqou

Description

@joshqou

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)
}

Metadata

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