dart-course icon indicating copy to clipboard operation
dart-course copied to clipboard

operators.dart Typecase example throws "type 'int' is not a subtype of type 'String' in type cast" error

Open TonyLovesDevOps opened this issue 2 years ago • 0 comments

This code throws the error:

var number = 23 as String; // throws "type 'int' is not a subtype of type 'String' in type cast" error
number is String; // true

I only tested in dart 2.18 and 2.17, and the error is the same in both.

Here's a dartpad showing a repro.

TonyLovesDevOps avatar Dec 11 '22 13:12 TonyLovesDevOps