Skip to content

Maybe NonEmpty types in a tuple do not generate the expected nullable / undefined values in corresponding Typescript list #49

@kallevmercury

Description

@kallevmercury

Type Example

data WidgetActionPayload
  = Activate (Maybe SparkLevel)
  | Reject Text [PromptKey]
  | Defer Text [PromptKey]
  | InfoRequest Text [PromptKey] (Maybe (NonEmpty ExtraInputPrompt))
  | UnknownResult Model.VoidData
  deriving stock (Show, Eq, Data)

Output Being Generated

contents: [string, string[], TExtraInputPrompt[]]

Expected Output

contents: [string, string[], TExtraInputPrompt[] | null]

or

contents: [string, string[], TExtraInputPrompt[] | undefined]

Testing

I tried to write a new test case for this to help replicate the issue (#48):

1) Generic instances TestMaybeTuple should handle Maybe in tuples correctly
       expected: [TSTypeAlternatives {
                   typeName = "IConWithMaybe",
                   typeGenericVariables = [],
                   alternativeTypes = ["[string, number[], string[]]"],
                   typeDoc = Nothing
                 }, TSTypeAlternatives {
                   typeName = "ISimpleConstructor",
                   typeGenericVariables = [],
                   alternativeTypes = ["string"],
                   typeDoc = Nothing
                 }, TSInterfaceDeclaration {
                   interfaceName = "IConWithMaybe",
                   interfaceGenericVariables = [],
                   interfaceMembers = [TSField {
                 @@ 4 lines omitted @@
                 }, TSField {
                   fieldOptional = False,
                   fieldName = "contents",
                   fieldType = "IConWithMaybe",
                   fieldDoc = Nothing
                 }],
                   interfaceDoc = Nothing
                 @@ 21 lines omitted @@
                 
        but got: [TSInterfaceDeclaration {
                   interfaceName = "IConWithMaybe",
                   interfaceGenericVariables = [],
                   interfaceMembers = [TSField {
                 @@ 4 lines omitted @@
                 }, TSField {
                   fieldOptional = False,
                   fieldName = "contents",
                   fieldType = "[string, number[], string[]]",
                   fieldDoc = Nothing
                 }],
                   interfaceDoc = Nothing
                 @@ 21 lines omitted @@

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions