Skip to content

Are Generic types not actual types? #858

Answered by bioball
rohan-datar asked this question in Q&A
Discussion options

You must be logged in to vote

The issue you're running into here is that types aren't values.

When defining a converter, you're actually asked to provide a class value, and not a type. Here's the API docs for converters: https://pkl-lang.org/package-docs/pkl/current/base/ValueRenderer.html#converters

So, in the below snippet:

converters {
  [String] = (it) -> /* etc */
}

We are defining a mapping entry whose key, String is referencing an object of type Class. It's not actually a type. That's also why Pkl is erroring when you define this key:

    [Listing<String>] = (i) -> toInt(i)

This is invalid syntax, because Listing<String> cannot be interpreted as a value. And, going a little further, Pkl's converters don't provi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@rohan-datar
Comment options

@bioball
Comment options

Answer selected by rohan-datar
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