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 exact semantics of JS types currently depend on their backend implementation. JS backends currently support conflating Dart types and JS types, whereas Wasm backends do not. Over time we will try and unify backend semantics as much as possible.

WARNING: The following types will be sealed in the near future. Do not subtype the types in this library as the subtypes will be broken.

Classes

JS
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.
JSPromiseToFuture
JSPromise -> Future<JSAny?>.
JSStringToString
JSString <-> String
JSUint16ArrayToInt16List
JSUint16Array <-> Uint16List
JSUint32ArrayToUint32List
JSUint32Array <-> Uint32List
JSUint8ArrayToUint8List
JSUint8Array <-> Uint8List
JSUint8ClampedArrayToUint8ClampedList
JSUint8ClampedArray <-> Uint8ClampedList
ListToJSArray
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

Typedefs

JSAny = JSAny
The overall top type in the JS types hierarchy.
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.