nestia icon indicating copy to clipboard operation
nestia copied to clipboard

Using ``type`` instead of ``interface`` does not generate the same schemas name

Open loucass003 opened this issue 7 months ago • 3 comments

Summary

Using a type instead of an interface does not generate the same schemas

  • Expected behavior: the two types should either have the same names or we should have a way to specify the name

  • Actual behavior:

The name of the schemas differ

Code occuring the bug

/**
 * Text conmtent of a landing page
 */
export interface LandingText {
  /**
   * unique key of the landing
   */
  slug: string & Slug;

  /**
   * json containing the text of the landing
   */
  text: LandingContent;

  /**
   * date of the first insertion in database
   */
  createdAt: Date;

  /**
   * date of last modification in database
   */
  updatedAt: Date;
}

// This will create a schema called -> PartialOmitLandingTextslugcreatedAtupdatedAt
export type EditableLandingText = Partial<
  Omit<LandingText, 'slug' | 'createdAt' | 'updatedAt'>
>;

// This will create a schema called -> EditableLandingText
export interface EditableLandingText
  extends Partial<Omit<LandingText, 'slug' | 'createdAt' | 'updatedAt'>> {}

loucass003 avatar Nov 30 '23 14:11 loucass003

Only typia.json.application() function get the exact alias name of it, but other validation functions are not.

It's because in the TypeScript compiler API, the type means an alias of another type.

samchon avatar Nov 30 '23 16:11 samchon

What about a way to name a schema from a tag?

export type EditableLandingText = Partial<
  Omit<LandingText, 'slug' | 'createdAt' | 'updatedAt'>
> & tags.Name<"EditableLandingText">;

that would also be helpfull for type definitions like


interface A {
   var1: string
   var2: {
     fi: string
     fa: string
     fo: string
   } & tags.Name<'MyCustomName'>  // Would have been called _type.01 otherwise
}

because currently the it also name the sub schemas in those cases _type.01

Maybe this is too much overhead idk. I will also be fine with using interface all the time instead of type. As you said if type is an alias it makes sense that typescript does not keep track of the name and just replace it on the spot.

loucass003 avatar Nov 30 '23 19:11 loucass003

Well, the way using type tag seems more terrible.

It would be better to finding the detour way for only one object alias type case by hard coding \o/.

Wait a week please.

samchon avatar Dec 01 '23 09:12 samchon