Type conversion

All the code we've seen so far was based on the automatic type conversion that happens inside the dart:js library. This conversion always happens in both directions. Once you know how this happens, you will have a better understanding of the limits of that solution and it will help you avoid mistakes.

Direct type conversion

Dart supports the following small subset of types by directly converting them from the JavaScript types:

  • null, bool, num, String, and DateTime (basic types)
  • Blob
  • Event
  • HtmlCollection
  • ImageData
  • KeyRange
  • Node
  • NodeList
  • TypedData (including its subclasses such as Int32List, but not ByteBuffer)
  • Window

Here is set of different types of JavaScript variables that we prepared in the JavaScript file:

var v_null = null; var v_bool = ...

Get Dart: Scalable Application Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.