-
-
Notifications
You must be signed in to change notification settings - Fork 161
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 nicer compiler errors when assigning a parameter to type LuckyAction.class
#1243
Comments
An example of doing this with a generic: class UI::Button(T) < BaseComponent
needs title : String
needs action : T
def render
link title, to: action, class: "btn"
end
end And class UI::Button < BaseComponent
def render
with_defaults class: "btn" do |button_builder|
yield button_builder
end
end
end
# Call *any* tag method. `link`, `button`, etc.
m UI::Button, &.link("My link, to: App::Show) |
Although not preferred, the usage of the generic version does look a bit nicer if you aren't used to blocks. I guess it would just depend how flexible/reusable you want your component to be. To complete the example above here's the usage of the generic. m UI::Button, title: "My Link", to: App::Show and your m UI::Button, &.link "My link", to: App::Show |
@neutrinog I agree it looks nicer especially if you are new to blocks. The downside is that you can't do something like this with the generic version since it uses a different tag than an m UI::Button, &.submit("Save my form") I think adding parens around the block helps a bit so I'm going to start doing that form now on to hopefully clarify things a bit. We'll see : |
@paulcsmith Wrong tag I think 😛 |
Oops! Sorry @neurodynamic! |
It seems like folks often want to write wrappers that can handle links, and will leverage the
link_helper.cr
definitions to figure out what to ask for in a parameter.Something like this:
Called like this:
Generates this cryptic compiler error:
Here's why, as noted in our Gitter:
Alllllll that context provided, I think it'd be really great if Lucky could step in and help out here when it seems that someone is trying to type-check a parameter with a
Lucky::Action.class
. Something like:The message needs some work, but the gist is that Lucky could point users towards what they want based on the use cases for checking a
LuckyAction.class
.The text was updated successfully, but these errors were encountered: