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

Name conflict in generated types #86

Open
bradleyayers opened this issue Feb 21, 2018 · 12 comments
Open

Name conflict in generated types #86

bradleyayers opened this issue Feb 21, 2018 · 12 comments

Comments

@bradleyayers
Copy link

I have a table document with a column type of type document_type:

CREATE TYPE document_type AS ENUM (
    'NOTE',
    'PAGE'
);
CREATE TABLE document (
    id uuid NOT NULL,
    document_type document_type NOT NULL
);

This causes a name conflict in the generate types:

export type document_type = "NOTE" | "PAGE";

// ...

export namespace documentFields {
  export type id = string;
  export type document_type = document_type;
  //          ^^^^^^^^^^^^^
  // Type alias 'note_type' circularly references itself
}
@abenhamdine
Copy link
Contributor

To avoid that, I think enums could be generated in PascalCase (after all it's the common practice with typescript) and/or with Enum prefix, something like :

export type EnumDocumentType = "NOTE" | "PAGE";

export namespace documentFields {
  export type id = string;
  export type document_type = EnumDocumentType;
}

@bradleyayers
Copy link
Author

I like that proposal, nice and simple!

@abenhamdine
Copy link
Contributor

It will be a breaking change though, because someone could have imported an enum and used it in its code.

@bradleyayers
Copy link
Author

Perhaps an option/flag then?

@abenhamdine
Copy link
Contributor

@xiamx what do you think on it ?
Personnaly, I'm -1 on putting this behind a flag because options complexify config and code.

It seems better to include it in next major version (while I doubt many users have enums and import them).

@xiamx
Copy link
Contributor

xiamx commented Feb 21, 2018

Yes, preferring a major version bump to have Enum in PascalCase.
We need a minimal impact solution to handle name collision for the current major version.

@bradleyayers
Copy link
Author

Emitting exports for both snake and camel, but using camel in the interfaces should work

@xiamx
Copy link
Contributor

xiamx commented Feb 21, 2018

Nice, that should provide a smooth transition.

bradleyayers added a commit to bradleyayers/schemats that referenced this issue Mar 10, 2018
@hinderberg
Copy link

Whats the status on this?

@bradleyayers
Copy link
Author

bradleyayers commented Feb 18, 2019

I'm using a forked version that I have checked into my project with this fix applied.

@hinderberg
Copy link

Thats to bad! Renaming my enum type while waithing for this. Forking too many libs allready! ;)

@felixmosh
Copy link

Why not export the enums and all table related interfaces under namespace with the name of the table.

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

No branches or pull requests

5 participants