Fable
Fable copied to clipboard
[TypeScript] generic parameters are duplicated
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 {
fable 4.21
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