Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7358c02

Browse files
committedMar 27, 2017
emit enums as union types
1 parent 0dea4f5 commit 7358c02

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
 

‎TS.fsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,11 @@ module Emit =
717717
// Name of an interface / enum / dict. Just return itself
718718
if allInterfacesMap.ContainsKey objDomType ||
719719
allCallbackFuncs.ContainsKey objDomType ||
720-
allDictionariesMap.ContainsKey objDomType then
720+
allDictionariesMap.ContainsKey objDomType ||
721+
allEnumsMap.ContainsKey objDomType then
721722
objDomType
722723
// Name of a type alias. Just return itself
723724
elif typeDefSet.Contains objDomType then objDomType
724-
// Enum types are all treated as string
725-
elif allEnumsMap.ContainsKey objDomType then "string"
726725
// Union types
727726
elif objDomType.Contains(" or ") then
728727
let allTypes = objDomType.Trim('(', ')').Split([|" or "|], StringSplitOptions.None)
@@ -883,7 +882,8 @@ module Emit =
883882
GetCallbackFuncsByFlavor flavor |> Array.iter emitCallBackFunction
884883

885884
let EmitEnums () =
886-
let emitEnum (e: Browser.Enum) = Pt.Printl "declare var %s: string;" e.Name
885+
let emitEnum (e: Browser.Enum) =
886+
Pt.Printl "type %s = %s;" e.Name (String.Join(" | ", e.Values |> Array.map (fun value -> "\"" + value + "\"")))
887887
browser.Enums |> Array.iter emitEnum
888888

889889
let EmitEventHandlerThis flavor (prefix: string) (i: Browser.Interface) =
@@ -1484,6 +1484,7 @@ module Emit =
14841484
| _ -> ()
14851485

14861486
EmitTypeDefs flavor
1487+
EmitEnums()
14871488

14881489
fprintf target "%s" (Pt.GetResult())
14891490
target.Flush()

0 commit comments

Comments
 (0)
Please sign in to comment.