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

[TypeScript] generic parameters are duplicated #3911

Open
goswinr opened this issue Sep 30, 2024 · 1 comment
Open

[TypeScript] generic parameters are duplicated #3911

goswinr opened this issue Sep 30, 2024 · 1 comment

Comments

@goswinr
Copy link
Contributor

goswinr commented Sep 30, 2024

This generates invalid typescript:

open System.Collections.Generic

type Table<'K,'V when 'K:equality> () =

    let dic = new Dictionary<'K,'V>()

    let addKeyValue key value =
        dic.[key] <- value        
   
    member _.add key value = 
        addKeyValue key value 

see REPL

The generic parameters K and V appear twice each in:
export function Table$2__addKeyValue<K, V, K, V>(this$: Table$2<K, V>, key: K, value: V): void {

image

fable 4.21

@goswinr
Copy link
Contributor Author

goswinr commented Oct 1, 2024

A workaround is to move internal functions of the class outside the class and inline them:

open System.Collections.Generic

let inline private addKeyValue (dic:Dictionary<'K,'V>) key value = // internal function moved here
    dic.[key] <- value  

type Table<'K,'V when 'K:equality> () =

    let dic = new Dictionary<'K,'V>()      
   
    member this.Add(key, value) = 
        addKeyValue dic key value 

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

1 participant