schemats
schemats copied to clipboard
Name conflict in generated types
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
}
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;
}
I like that proposal, nice and simple!
It will be a breaking change though, because someone could have imported an enum and used it in its code.
Perhaps an option/flag then?
@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).
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.
Emitting exports for both snake and camel, but using camel in the interfaces should work
Nice, that should provide a smooth transition.
Whats the status on this?
I'm using a forked version that I have checked into my project with this fix applied.
Thats to bad! Renaming my enum type while waithing for this. Forking too many libs allready! ;)
Why not export the enums and all table related interfaces under namespace with the name of the table.