Skip to content

Inconsistent type inference for additionalProperties when properties is also defined #199

@alvis

Description

@alvis

Encountering a bug in json-schema-to-ts version 3.1.0 where the handling of additionalProperties does not work as expected when properties is also provided. Instead of assigning the designated type to additional properties, they are treated as unknown.

Example to reproduce:

import type { FromSchema } from 'json-schema-to-ts';

type Output = FromSchema<{
  type: 'object';
  additionalProperties: { type: 'string' };
  properties: {
    something: { type: 'string' };
  };
}>;

Expected behavior:

type Output = {
    [x: string]: string | undefined;
    something?: string | undefined;
}

Actual behavior:

type Output = {
    [x: string]: unknown;
    something?: string | undefined;
}

The expected behavior would be to treat all additional properties as string or string | undefined (which makes more sense when it comes to dealing with the unknown and type compliant to the non required additional properties), aligning with the specified additionalProperties type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions