Skip to content

Commit 388f252

Browse files
committed
Merge pull request #38 from Microsoft/fixDictionaryIssue
Detect changes in json files regarding dictionary types
2 parents edbc914 + f18a8dd commit 388f252

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

TS.fsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,26 @@ let EmitDictionaries flavor =
531531
| "Object" -> Pt.printl "interface %s {" dict.Name
532532
| _ -> Pt.printl "interface %s extends %s {" dict.Name dict.Extends
533533

534+
let emitJsonProperty (p: ItemsType.Root) =
535+
Pt.printl "%s: %s;" p.Name.Value p.Type.Value
536+
537+
let removedPropNames =
538+
getRemovedItems ItemKind.Property flavor
539+
|> Array.filter (matchInterface dict.Name)
540+
|> Array.map (fun rp -> rp.Name.Value)
541+
|> Set.ofArray
542+
let addedProps =
543+
getAddedItems ItemKind.Property flavor
544+
|> Array.filter (matchInterface dict.Name)
545+
534546
Pt.increaseIndent()
535-
dict.Members |> Array.iter (fun m -> Pt.printl "%s?: %s;" m.Name (DomTypeToTsType m.Type))
547+
Array.iter emitJsonProperty addedProps
548+
dict.Members
549+
|> Array.filter (fun m -> not (Set.contains m.Name removedPropNames))
550+
|> Array.iter (fun m ->
551+
match (findOverriddenItem m.Name ItemKind.Property dict.Name) with
552+
| Some om -> emitJsonProperty om
553+
| None -> Pt.printl "%s?: %s;" m.Name (DomTypeToTsType m.Type))
536554
Pt.decreaseIndent()
537555
Pt.printl "}"
538556
Pt.printl ""

0 commit comments

Comments
 (0)