Last active
May 27, 2022 17:02
-
-
Save lukepighetti/32b262df2ec7dbb5ccf437ce63947388 to your computer and use it in GitHub Desktop.
How to check if one type is a supertype of any other type. Credit: https://twitter.com/TheKnaecke/status/1530225626019512323
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
void main() { | |
print(isSupertype<BaseClass, SuperClass>()); // true | |
} | |
class SuperClass extends BaseClass {} | |
abstract class BaseClass {} | |
bool isSupertype<Subtype, Supertype>() => <Supertype>[] is List<Subtype>; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment