joi-to-typescript icon indicating copy to clipboard operation
joi-to-typescript copied to clipboard

Redundant typing

Open kingmesal opened this issue 2 years ago • 1 comments

I found an issue, which I think is related to #53

Starting Schema - schema/Base.ts

export const InteractionTypeSchema = Joi.string().valid("CREATE", "DELETE", "UPDATE")
    .meta({ className: 'InteractionType' });

export const InteractionSchema = Joi.object({
    companyId: Joi.string().required(),
    userId: Joi.string().required(),
    appVersion: Joi.string().required(),
    interactionType: InteractionTypeSchema,
})
    .meta({ className: 'Interaction' });

Generates - interfaces/Base.ts

export interface Interaction {
  appVersion: string;
  companyId: string;
  interactionType?: InteractionType | 'CREATE' | 'DELETE' | 'UPDATE';
  userId: string;
}

export type InteractionType = 'CREATE' | 'DELETE' | 'UPDATE';

I think interactionType should only reference InteractionType and not CREATE, DELETE, UPDATE

kingmesal avatar Aug 08 '22 14:08 kingmesal

I was just about to file an identical issue with basically exactly the same example code. Even though this has no impact in practice, it makes interfaces really ugly and confusing. Bug is present in 4.0.5.

henhal avatar Sep 23 '22 06:09 henhal

Duplicate of issue #149

mrjono1 avatar Mar 28 '23 10:03 mrjono1