Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Last active May 27, 2022 17:02
Show Gist options
  • Save lukepighetti/32b262df2ec7dbb5ccf437ce63947388 to your computer and use it in GitHub Desktop.
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
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