diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index d89d6adef..352aca555 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [All] Fixed Fable compiler hanging on some errors (#3842) (by @ncave) * [JS/TS] Fixed DateTime.MinValue, DateTime.MaxValue (#3836) (by @ncave) +* [JS/TS] Fixed missing field using TypeScriptTaggedUnion (#3837) (by @ncave) ## 4.19.0 - 2024-06-10 diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index e4cb8e414..20e07be54 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -134,8 +134,9 @@ type FsUnionCase(uci: FSharpUnionCase) = | _ -> None ) - static member HasNamedFields(uci: FSharpUnionCase) = - not (uci.Fields.Count = 1 && uci.Fields[0].Name = "Item") + // static member HasNamedFields(uci: FSharpUnionCase) = + // not (uci.Fields.Count = 1 && uci.Fields[0].Name = "Item") + // true interface Fable.UnionCase with member _.Name = uci.Name diff --git a/src/Fable.Transforms/FSharp2Fable.fs b/src/Fable.Transforms/FSharp2Fable.fs index 22a134c04..fd8e48fcf 100644 --- a/src/Fable.Transforms/FSharp2Fable.fs +++ b/src/Fable.Transforms/FSharp2Fable.fs @@ -74,7 +74,7 @@ let private transformNewUnion com ctx r fsType (unionCase: FSharpUnionCase) (arg | TypeScriptTaggedUnion(_, _, tagName, rule) -> match argExprs with - | [ argExpr ] when not (FsUnionCase.HasNamedFields unionCase) -> argExpr + // | [ argExpr ] when not (FsUnionCase.HasNamedFields unionCase) -> argExpr | _ -> let isCompiledValue, tagExpr = match FsUnionCase.CompiledValue unionCase with @@ -1176,16 +1176,16 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) appliedGenArgs fs return Fable.Get(unionExpr, Fable.TupleIndex index, fieldType, r) | TypeScriptTaggedUnion _ -> - if FsUnionCase.HasNamedFields unionCase then - let kind = - Fable.FieldInfo.Create( - FsField.FSharpFieldName field, - fieldType = makeType Map.empty field.FieldType - ) + // if not (FsUnionCase.HasNamedFields unionCase) then + // return unionExpr + // else + let kind = + Fable.FieldInfo.Create( + FsField.FSharpFieldName field, + fieldType = makeType Map.empty field.FieldType + ) - return Fable.Get(unionExpr, kind, fieldType, r) - else - return unionExpr + return Fable.Get(unionExpr, kind, fieldType, r) | StringEnum _ -> return "StringEnum types cannot have fields" diff --git a/src/Fable.Transforms/Fable2Babel.fs b/src/Fable.Transforms/Fable2Babel.fs index b587877e9..a2766ff1e 100644 --- a/src/Fable.Transforms/Fable2Babel.fs +++ b/src/Fable.Transforms/Fable2Babel.fs @@ -852,12 +852,12 @@ module Annotation = AbstractMember.abstractProperty (prop, tagType, isComputed = isComputed) match uci.UnionCaseFields with - | [ field ] when field.Name = "Item" -> - IntersectionTypeAnnotation - [| - field.FieldType |> resolveInlineType genArgs |> makeFieldAnnotation com ctx - ObjectTypeAnnotation [| tagMember |] - |] + // | [ field ] when field.Name = "Item" -> + // IntersectionTypeAnnotation + // [| + // field.FieldType |> resolveInlineType genArgs |> makeFieldAnnotation com ctx + // ObjectTypeAnnotation [| tagMember |] + // |] | fields -> let names, types = fields |> List.map (fun fi -> fi.Name, fi.FieldType) |> List.unzip