-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
In my company and personal projects I've seen typedefs for things like List<SomeType> and other types with generics. Some of the time they come with extensions for helper methods.
I'd like to request a refactor that would convert a typedef into an extension type so that in cases like this we can move the extension declarations over to the new extension type to increase code clarity and enhance type safety by consolidating related functionality into a unified structure.
For most types we could add implements Type but we'd need to be careful with Records and Functions since that is not possible - Never too even though I doubt someone has ever used typedef with it (dart-lang/language#3839).
Asking for a refactor and not an assist since we'd probably need to add constructors around existing implicit assignments. E.g:
typedef Id = String;
Id getId() => 'foo';
Id otherId() => 1 == 1 ? 'bar' : getId();Would become:
extension type Id(String inner) implements String {}
Id getId() => Id('foo');
Id otherId() => Id(1 == 1 ? 'bar' : getId());Not sure about the placement here but that would be a discussion here.
Somewhat related:
- Constructor placement ->
unnecessary_castquick-fix unexpected result in switch expression #56072 - Adding constructor -> "Add cast" fix places cast in wrong place for extension type on list #56946