fable-compiler / ts2fable

Parser of Typescript declaration files
http://fable.io/ts2fable/
Apache License 2.0
224 stars 34 forks source link

Error on DUs with same names but Lower & UpperCase #255

Open robkuz opened 6 years ago

robkuz commented 6 years ago

Hey,

I found this in @types/DocumentDB

export type TriggerType = 'Pre' | 'Post' | 'pre' | 'post';
export type TriggerOperation = 'All' | 'Create' | 'Update' | 'Delete' | 'Replace' | 'all' | 'create' | 'update' | 'delete' | 'replace';

this is converted into the following F#

type [<StringEnum>] [<RequireQualifiedAccess>] TriggerType =
| [<CompiledName "Pre">] Pre
| [<CompiledName "Post">] Post
| Pre
| Post

type [<StringEnum>] [<RequireQualifiedAccess>] TriggerOperation =
| [<CompiledName "All">] All
| [<CompiledName "Create">] Create
| [<CompiledName "Update">] Update
| [<CompiledName "Delete">] Delete
| [<CompiledName "Replace">] Replace
| All
| Create
| Update
| Delete
| Replace

Which is clearly wrong as there is now 2 value constructors with the exact name whereas the Typescript ones have differences in lower case vs upper case.

humhei commented 6 years ago

I am also not clear how to solve this special case 😕

type  [<StringEnum>] [<RequireQualifiedAccess>] TriggerOperation =
| [<CompiledName "create">] CreateLowerCase
| [<CompiledName "update">] UpdateLowerCase
| [<CompiledName "delete">] DeleteLowerCase
| [<CompiledName "all">] ReplaceLowerCase
| All
| Create
| Update
| Delete
| Replace

Any other ones have better solutions?

robkuz commented 6 years ago

My proposal would be

A) if this is a string enum on the TS side we could assume (heuristically) that the same value constructors with different casings are just there so the typical TS developer can push anything they want into the api (Pre, pre or PRE for example) and then it doesn't matter if we just offer ONE value

or if we would assume that those different cases have a different meaning then

B) you we prefix the values

type [<StringEnum>] [<RequireQualifiedAccess>] TriggerType =
| [<CompiledName "Pre">] Pre
| [<CompiledName "Post">] Post
| [<CompiledName "pre">] LC_Pre
| [<CompiledName "post">] LC_Post