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

Add support for ActiveRecord enums #23

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Conversation

Envek
Copy link
Contributor

@Envek Envek commented Nov 15, 2024

Output enum values in TS types.

Given that ActiveRecord model declares enum column:

class Post < ApplicationRecord
  enum category: [:news, :article, :blog].index_by(&:itself)
end

Output enum keys as a possible values instead of generic type.

-  category?: string | null;
+  category?: "news" | "article" | "blog" | null;

typelize directive accepts enum option that overrides enum values from the model or suppresses it if false is given.

typelize category: [:string, enum: %i[whatever else]]

@skryukov skryukov merged commit aea764b into skryukov:main Nov 15, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants