Last active
March 21, 2025 13:28
-
-
Save frank-weindel/9831b2f4baa79f9e067dfbf70009f88b to your computer and use it in GitHub Desktop.
Dart Extension Types as Map Keys (Be Careful)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension type ChannelId(String value) {} | |
extension type StationId(String value) {} | |
extension type SomeNumberId(int value) {} | |
Map<ChannelId, String> tvChannelNames = {ChannelId('123'): 'NBC'}; | |
void main() { | |
print(tvChannelNames[StationId('123')]); // No Error! | |
print(tvChannelNames[SomeNumberId(123)]); // No Error! | |
print(tvChannelNames[123]); // collection_methods_unrelated_type lint rule | |
print(tvChannelNames["123"]); // collection_methods_unrelated_type lint rule | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment