dart:js_interop library

A library for JS interop. Includes a JS type hierarchy to facilitate sound interop with JS. The JS type hierarchy is modeled after the actual type hierarchy in JS, and not the Dart type hierarchy.

Note: The JS types that are exposed through this library are currently wrapper types that are erased to their runtime types. The runtime types will differ based on the backend. In general, stick to using conversion functions that are exposed as extension methods e.g. 'toJS'.

WARNING: This library is still a work in progress. As such, JS types, allowed syntax, semantics, and functionality may all change, so avoid using this library in production.

Classes

JS
The annotation for JS interop members.
JSExport
Annotation to mark Dart classes as exportable and allow instance members to be wrapped with an object literal.
ObjectLiteral
The annotation for object literal constructors.

Extensions

BoolToJSBoolean
ByteBufferToJSArrayBuffer
ByteDataToJSDataView
DoubleToJSNumber
Float32ListToJSFloat32Array
Float64ListToJSFloat64Array
FunctionToJSExportedDartFunction
Int16ListToJSInt16Array
Int32ListToJSInt32Array
Int8ListToJSInt8Array
JSArrayBufferToByteBuffer
JSArrayBuffer <-> ByteBuffer
JSArrayToList
JSArray <-> List
JSBooleanToBool
JSBoolean <-> bool
JSDataViewToByteData
JSDataView <-> ByteData
JSExportedDartFunctionToFunction
JSExportedDartFunction <-> Function
JSExportedDartObjectToObject
JSExportedDartObject <-> Object
JSFloat32ArrayToFloat32List
JSFloat32Array <-> Float32List
JSFloat64ArrayToFloat64List
JSFloat64Array <-> Float64List
JSInt16ArrayToInt16List
JSInt16Array <-> Int16List
JSInt32ArrayToInt32List
JSInt32Array <-> Int32List
JSInt8ArrayToInt8List
JSInt8Array <-> Int8List
JSNumberToDouble
JSNumber <-> double.
JSObjectUtilExtension
Utility extensions for JSObject.
JSPromiseToFuture
JSPromise -> Future<JSAny?>.
JSStringToString
JSString <-> String
JSUint16ArrayToInt16List
JSUint16Array <-> Uint16List
JSUint32ArrayToUint32List
JSUint32Array <-> Uint32List
JSUint8ArrayToUint8List
JSUint8Array <-> Uint8List
JSUint8ClampedArrayToUint8ClampedList
JSUint8ClampedArray <-> Uint8ClampedList
ListToJSArray
NullableObjectUtilExtension
Utility extensions for Object?.
NullableUndefineableJSAnyExtension
JSUndefined and JSNull are actual reified types on some backends, but not others. Instead, users should use nullable types for any type that could contain JSUndefined or JSNull. However, instead of trying to determine the nullability of a JS type in Dart, i.e. using ?, !, != null or == null, users should use the provided helpers below to determine if it is safe to downcast a potentially JSNullable or JSUndefineable object to a defined and non-null JS type.
NumToJSExtension
num -> JSNumber.
ObjectToJSExportedDartObject
StringToJSString
Uint16ListToJSInt16Array
Uint32ListToJSUint32Array
Uint8ClampedListToJSUint8ClampedArray
Uint8ListToJSUint8Array

Constants

anonymous → const _Anonymous
An annotation that indicates a JS annotated class is structural and does not have a known JavaScript prototype.
_Anonymous()
staticInterop → const _StaticInterop
staticInterop enables the JS annotated class to be treated as a "static" interop class.
_StaticInterop()

Properties

globalJSObject JSObject
A getter to retrieve the Global JSObject.
read-only

Typedefs

JSAny = JSAny
The JS types users should use to write their external APIs.
JSArray = JSArray
The type of all JS arrays, JSArray <: JSObject.
JSArrayBuffer = JSArrayBuffer
The type of JS array buffers, JSArrayBuffer <: JSObject.
JSBoolean = JSBoolean
The type of JS booleans, JSBoolean <: JSAny.
JSDataView = JSDataView
The type of JS byte data, JSDataView <: JSObject.
JSExportedDartFunction = JSExportedDartFunction
The type of all Dart functions adapted to be callable from JS. We only allow a subset of Dart functions to be callable from JS, JSExportedDartFunction <: JSFunction.
JSExportedDartObject = JSExportedDartObject
The type of all Dart objects exported to JS. If a Dart type is not explicitly marked with @JSExport, then no guarantees are made about its representation in JS. JSExportedDartObject <: JSObject.
JSFloat32Array = JSFloat32Array
JSFloat64Array = JSFloat64Array
JSFunction = JSFunction
The type of all JS functions, JSFunction <: JSObject.
JSInt16Array = JSInt16Array
JSInt32Array = JSInt32Array
JSInt8Array = JSInt8Array
The typed arrays themselves, *Array <: JSTypedArray.
JSNumber = JSNumber
The type of JS numbers, JSNumber <: JSAny.
JSObject = JSObject
The representation type of all JavaScript objects for inline classes, JSObject <: JSAny.
JSPromise = JSPromise
The type of JS promises and promise-like objects, JSPromise <: JSObject.
JSString = JSString
The type of JS strings, JSString <: JSAny.
JSTypedArray = JSTypedArray
The abstract supertype of all JS typed arrays, JSTypedArray <: JSObject.
JSUint16Array = JSUint16Array
JSUint32Array = JSUint32Array
JSUint8Array = JSUint8Array
JSUint8ClampedArray = JSUint8ClampedArray
JSVoid = void
The type of JSUndefined when returned from functions. Unlike pure JS, no actual object will be returned.