Skip to content

property valueClassBrand of type NNN is not assignable to string index type XXXX in declaration file (d.ts) #126

@sakari

Description

@sakari

oats generates a ts-ignore to the source file when the schema has object type with additionalFields: A where A is not any or unknown. This is because we use a phantom object property to brand types. The ts-ignore pragma circumvents typescript error about the field used for branding not matching the type of the string indexed field.

Sadly typescript does not keep the ts-ignore pragmas in the d.ts file it generates so the same type error happens when trying to use the generated code as a library. See microsoft/TypeScript#38628

The workaround to this is to postprocess the d.ts file and add the ignore back there. The index key name is always the same so finding it from the d.ts file should be easy.

If this becomes a major issue we could export some helpers to deal with this.

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