Skip to content

Incorrect import type and value space reference in const+typeof generation for schemas with both enum and const #2624

@ioslh

Description

@ioslh

When a schema property has both enum and const fields, and the schema contains only properties
with const values, orval generates incorrect TypeScript code with two issues:

  1. Wrong import statement: Uses import type instead of import for enum constants used as
    values
  2. Type/value space confusion: References enum type name as a value in const object
import type { AType } from './aType';

export const AValue = {
  type: AType, // 'AType' cannot be used as a value because it was imported using 'import type'.
} as const;
export type A = typeof AValue;

Reproduction

See minimal reproduction example: https://github.com/ioslh/temp-orval-generate

You can clone the repo and run npm run generate to see the generated result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions