Skip to main content

toJs()

toJs(dart, check): any

Converts a Dart object to its JavaScript wrapper or native JS value.

Type conversion rules:

  • null/undefined -> passed through
  • FLOAT_NULL sentinel -> null
  • Map -> plain object with recursively converted values
  • List -> array via paramsToJs
  • DG.TypedEventArgs -> TypedEventArgs wrapper
  • DateTime -> dayjs object
  • ByteArray -> passed through unchanged
  • BigInt -> JavaScript BigInt
  • Objects with existing wrappers -> returns the wrapper
  • Property -> Property wrapper

Parameters

ParameterTypeDefault valueDescription
dartanyundefinedDart object handle
checkbooleanfalseWhen true, throws an exception if the type cannot be converted

Returns

any

JavaScript wrapper, native JS value, or the original Dart handle

Throws

Error if check is true and type is not supported

See

  • toDart for the reverse operation
  • ./dart-interop.md for full documentation

Source

src/wrappers_impl.ts:60