Skip to content

Is generic code is not supported in Skip #11

Answered by marcprux
DominatorVbN asked this question in Q&A
Discussion options

You must be logged in to vote

The Skip transpiler supports many Swift generic constructs, but not everything. We are constrained by Kotlin's limitations, and in this case the limitations of reified type parameters on the JVM (which famously implements generics though type erasure, and thus cannot provide runtime information about the types based on the signature alone).

This is one such limitation: you can't reference T.self when all you have is a type parameter: you'll need an instance, or the type itself, to be passed as a parameter.

I think this might work:

    func fetch<T: Decodable>(typeParam: T.Self,
        api: TMDBAPI
    ) async throws -> T {
        let request = try api.getURLRequest()
        let (data, _) 

Replies: 2 comments 5 replies

Comment options

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

@pabloruan0710
Comment options

@sturmenta
Comment options

Answer selected by marcprux
Comment options

You must be logged in to vote
2 replies
@aabewhite
Comment options

@sturmenta
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
5 participants