ts2fable icon indicating copy to clipboard operation
ts2fable copied to clipboard

Error on DUs with same names but Lower & UpperCase

Open robkuz opened this issue 7 years ago • 2 comments

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.

robkuz avatar Aug 05 '18 10:08 robkuz

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?

humhei avatar Aug 05 '18 11:08 humhei

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

robkuz avatar Aug 05 '18 12:08 robkuz