Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic `is not` in Dart

Tags:

dart

Is there a more idiomaic way to express "is not" than !(o is T)?

/// Object (o) is not type (T)
/// 
/// Syntax that works but is not concise: `!(o is T)`

final word = 'drow';

if (!(word is String)) print('undoable');
like image 879
creativecreatorormaybenot Avatar asked Sep 15 '19 19:09

creativecreatorormaybenot


1 Answers

You can use o is! T:

if (word is! String) print('undoable');

See Type test operators.

like image 128
Alexandre Ardhuin Avatar answered Nov 01 '22 04:11

Alexandre Ardhuin