Skip to content

Record<sting, string | null> is being misinterpreted #1824

@fadiatamny

Description

@fadiatamny

Given a type of

export interface ObjectPartialFieldUpdate {
  tags?: Record<string, string | null> | null
}

it outputs the following rules

"tags": {"dataType":"union","subSchemas":[{"ref":"Record_string.string-or-null_"},{"dataType":"enum","enums":[null]}]},

where the Record_string.string-or-null_ is of type

"type": {"dataType":"nestedObjectLiteral","nestedProperties":{},"additionalProperties":{"dataType":"string"},"validators":{}},

which is incorrect as it does not allow null values in the record itself

Current workaround is to generate the type as

export interface ObjectPartialFieldUpdate {
  tags?: { [key: string]: string | null } | null
}

which generates the rule type of

 "tags": {"dataType":"union","subSchemas":[{"dataType":"nestedObjectLiteral","nestedProperties":{},"additionalProperties":{"dataType":"union","subSchemas":[{"dataType":"string"},{"dataType":"enum","enums":[null]}]}},{"dataType":"enum","enums":[null]}]},

which allows us to pass the follwoing payload

{
   tags:  { 
         test: null
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions