Skip to content

How can I typealias and/or extend a generic type such as Pair? #482

Answered by HT154
jjmaestro asked this question in Q&A
Discussion options

You must be logged in to vote

You've brushed up against an important core language feature of Pkl: types and methods have different namespaces. Methods can exist with the same name as types within the same module and pkl:base's Pair, List, and Map are a few examples of this.

In this case, you should be able to define a KV "constructor" method in your module to achieve what you're looking for:

function KV(key: String, value: Int): KV = Pair<String, Int>(key, value)

You can see that similar is done for Pair here:

external const function Pair<First, Second>(first: First, second: Second): Pair<First, Second>

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@jjmaestro
Comment options

@jjmaestro
Comment options

@jjmaestro
Comment options

Answer selected by jjmaestro
Comment options

You must be logged in to vote
1 reply
@jjmaestro
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants