From 7a9db876b02b23e5379d1e549e9a6924c3094df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0=20=D0=A3=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D1=97=D0=BD=D1=96!=20=D0=93=D0=B5=D1=80=D0=BE=D1=8F=D0=BC=20?= =?UTF-8?q?=D1=81=D0=BB=D0=B0=D0=B2=D0=B0!?= <777696+ncave@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:52:41 -0700 Subject: [PATCH] fix: missing `type` property for `TypeScriptTaggedUnion` cases with a single argument (#3844) Fix #3837 --- src/Fable.Cli/CHANGELOG.md | 1 + src/Fable.Transforms/FSharp2Fable.Util.fs | 5 +++-- src/Fable.Transforms/FSharp2Fable.fs | 20 ++++++++++---------- src/Fable.Transforms/Fable2Babel.fs | 12 ++++++------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index 07b3886d91..fa7162e215 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [All] Ignore testers for erased union cases (#3658) (by @ncave) * [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 1ec73744d8..41bf908e54 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 48c23cc8e6..48b63417b4 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 @@ -1179,16 +1179,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 b587877e9a..a2766ff1ef 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