Skip to content

Commit 5271a71

Browse files
[JS/TS] Fix #4025: No reflection for pojos (#4048)
Co-authored-by: Maxime Mangel <[email protected]>
1 parent b1541eb commit 5271a71

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/Fable.Cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
* [JS/TS] Fix #4025: No reflection info for pojos (by @alfonsogarciacaro)
1213
* [JS/TS] Fix #4049: decimal/bigint to integer conversion checks (by @ncave)
1314

1415
## 5.0.0-alpha.10 - 2025-02-16

src/Fable.Compiler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
* [JS/TS] Fix #4025: No reflection info for pojos (by @alfonsogarciacaro)
1213
* [JS/TS] Fix #4049: decimal/bigint to integer conversion checks (by @ncave)
1314

1415
## 5.0.0-alpha.10 - 2025-02-16

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,10 @@ module Reflection =
396396
|> List.toArray
397397

398398
match com.GetEntity(entRef) with
399-
| Patterns.Try (Util.tryFindAnyEntAttribute [ Atts.stringEnum; Atts.erase; Atts.tsTaggedUnion ]) (att, _) as ent ->
399+
| Patterns.Try (Util.tryFindAnyEntAttribute [ Atts.stringEnum
400+
Atts.erase
401+
Atts.tsTaggedUnion
402+
Atts.pojoDefinedByConsArgs ]) (att, _) as ent ->
400403
match att with
401404
| Atts.stringEnum -> primitiveTypeInfo "string"
402405
| Atts.erase ->

tests/Js/Main/JsInteropTests.fs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,27 @@ module TaggedUnion =
317317

318318
#if FABLE_COMPILER
319319
module PojoDefinedByConsArgs =
320-
open Fable.Core.JS
321-
322-
[<Pojo; AllowNullLiteral>]
320+
[<JS.Pojo; AllowNullLiteral>]
323321
type Person( name : string ) =
324322
member val name = name
325323

326-
[<Pojo; AllowNullLiteral>]
324+
[<JS.Pojo; AllowNullLiteral>]
327325
type User( id: int, name: string, ?age: int ) =
328326
inherit Person(name)
329327
member val id = id
330328
member val age = age with get, set
331329
member val name = name
332330

333-
[<Pojo; AllowNullLiteral>]
331+
type Team = {
332+
Leader: User
333+
}
334+
335+
[<JS.Pojo; AllowNullLiteral>]
334336
type BaseBag<'T>() =
335337
new ( bag : 'T) = BaseBag()
336338
member val bag: 'T = jsNative
337339

338-
[<Pojo; AllowNullLiteral>]
340+
[<JS.Pojo; AllowNullLiteral>]
339341
type UserBag<'ExtraData> private () =
340342
inherit BaseBag<int>()
341343
new ( bag : int, data: 'ExtraData, ?userId : int) = UserBag()
@@ -382,6 +384,17 @@ module PojoDefinedByConsArgs =
382384
user.age |> equal None
383385
user.age <- Some 42
384386
user.age |> equal (Some 42)
387+
388+
testCase "Declared types can reference Pojo class" <| fun _ ->
389+
let expected = [|"Fable.Tests.JsInterop.PojoDefinedByConsArgs.User"|]
390+
391+
FSharp.Reflection.FSharpType.GetRecordFields typeof<Team>
392+
|> Array.map (fun f -> f.PropertyType.FullName)
393+
|> equal expected
394+
395+
FSharp.Reflection.FSharpType.GetRecordFields typeof<{| Leader: User |}>
396+
|> Array.map (fun f -> f.PropertyType.FullName)
397+
|> equal expected
385398
]
386399
#endif
387400

0 commit comments

Comments
 (0)