Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
loucass003 opened this issue Nov 30, 2023 · 3 comments
Open
Assignees
Labels
question Further information is requested

Comments

@loucass003
Copy link
Contributor

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'>> {}
@samchon samchon self-assigned this Nov 30, 2023
@samchon samchon added the question Further information is requested label Nov 30, 2023
@samchon
Copy link
Owner

samchon commented Nov 30, 2023

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.

@loucass003
Copy link
Contributor Author

loucass003 commented Nov 30, 2023

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.

@samchon
Copy link
Owner

samchon commented Dec 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants