How to correctly typehint or set return types for IDE support and autocomplete?

Hi guys, I create small macro for all fields and entries:
// FilamentServiceProvider.php

ViewComponent::macro('warningHint', function (\Closure|bool|null $condition, \Closure|string|null $message): static {
return $this->hintIcon($condition ? 'heroicon-c-exclamation-triangle' : null)
->hintColor('yellow')
->hintIconTooltip($message);
});
// FilamentServiceProvider.php

ViewComponent::macro('warningHint', function (\Closure|bool|null $condition, \Closure|string|null $message): static {
return $this->hintIcon($condition ? 'heroicon-c-exclamation-triangle' : null)
->hintColor('yellow')
->hintIconTooltip($message);
});
But I still have these warnings: Method 'hintIcon' not found in FilamentServiceProvider|\Filament\Support\Components\ViewComponent Method 'warningHint' not found in \Filament\Forms\Components\Toggle
3 Replies
John Wink
John Wink7mo ago
Try this
Toggle::macro(‘warningHint’, function (\Closure|bool|null $condition, \Closure|string|null $message): static {
return $this->hintIcon($condition ? ‘heroicon-c-exclamation-triangle’ : null)
->hintColor(‘yellow’)
->hintIconTooltip($message);
});
Toggle::macro(‘warningHint’, function (\Closure|bool|null $condition, \Closure|string|null $message): static {
return $this->hintIcon($condition ? ‘heroicon-c-exclamation-triangle’ : null)
->hintColor(‘yellow’)
->hintIconTooltip($message);
});
because ViewComponent does not have the method hintIcon hintColour hintIconTooltip. You should check whether these methods are available in your target Component, if not it will not work there.
Trauma Zombie
Trauma ZombieOP7mo ago
Yeah, I know, but there is too many components that I want to use this. For example TextEntry, TextInput, Select, Toggle, Textarea, TextRich etc. I dont want to duplicate it.
John Wink
John Wink7mo ago
Then u should check before with method_exists
Want results from more Discord servers?
Add your server