diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index 240427a31..ef70e9d49 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [JS/TS/Python/Rust] Fixed String.StartsWith/EndsWith (#3934) (by @ncave) * [All/Rust] Removed Regex.Replace from hot paths (by @ncave) * [JS] Fix regression, generate `let` variable when using `import` on a private mutable variable (by @MangelMaxime) +* [TS] Prevent generics to be duplicated (by @MangelMaxime) ## 4.22.0 - 2024-10-02 diff --git a/src/Fable.Transforms/Fable2Babel.fs b/src/Fable.Transforms/Fable2Babel.fs index c0d9bbf1e..3f8123730 100644 --- a/src/Fable.Transforms/Fable2Babel.fs +++ b/src/Fable.Transforms/Fable2Babel.fs @@ -565,6 +565,7 @@ module Annotation = TypeParameter.typeParameter (name, ?bound = bound) |> Some | _ -> None ) + |> Array.distinct let makeTypeParamInstantiation (com: IBabelCompiler) ctx genArgs = if List.isEmpty genArgs then diff --git a/tests/Js/Main/DictionaryTests.fs b/tests/Js/Main/DictionaryTests.fs index 30a1385fb..29d7fb1f5 100644 --- a/tests/Js/Main/DictionaryTests.fs +++ b/tests/Js/Main/DictionaryTests.fs @@ -12,6 +12,17 @@ type MyRecord = { a: int } type R = { i: int; s: string } +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 + + member _.Dic = dic let tests = testList "Dictionaries" [ testCase "Dictionary KeyValuePattern works" <| fun () -> // See #509 @@ -251,4 +262,11 @@ let tests = equal cache.[typeof] 1 equal cache.[typeof] 2 equal cache.[typeof] 3 + + testCase "Check that generics are not duplicated " <| fun _ -> // See #3911 + let table = Table<_,_>() + table.add "A" 1 + table.add "B" 2 + table.add "C" 3 + table.Dic.Count |> equal 3 ]