dart:js_interop library

Interoperability, "interop" for short, with JavaScript and browser APIs.

JavaScript interop allows a Dart program to interact with a JavaScript runtime. This can, for example, be to access JavaScript declarations and interact with JavaScript values, or to adapt Dart values so that they can be passed to and used by JavaScript code.

This JavaScript interop library works by introducing an abstraction over JavaScript values, a Dart type hierarchy ("JS types") which mirrors known JavaScript types, and a framework for introducing new Dart types that bind Dart type declarations to JavaScript values and external member declarations to JavaScript APIs.

This abstraction allows the same interop API to be used both when the Dart code is compiled to JavaScript and when compiled to Wasm.

See https://dart.dev/interop/js-interop for more details on usage, types, and previous JavaScript interop.


The types defined in this library only provide static guarantees. The runtime types differ based on the backend, so it is important to rely on static functionality like the conversion functions, for example toJS and not runtime mechanisms like type checks (is) and casts (as). Similarly, identical may return different results for the same JS value depending on the compiler. Use == to check for equality of two JS types instead.


An annotation on a JavaScript interop declaration.
Annotation to allow Dart classes to be wrapped with a JS object using dart:js_interop's createJSInteropWrapper.

Extension Types

An opaque reference to a Dart object that can be passed to JavaScript.
A non-nullish JavaScript value.
A JavaScript Array.
A JavaScript ArrayBuffer.
A JavaScript BigInt.
A JavaScript boolean.
A Dart object that is wrapped with a JavaScript object so that it can be passed to JavaScript safely.
A JavaScript DataView.
A JavaScript callable function created from a Dart function.
A JavaScript Float32Array.
A JavaScript Float64Array.
A JavaScript Function value.
A JavaScript Int16Array.
A JavaScript Int32Array.
A JavaScript Int8Array.
A JavaScript number.
A JavaScript Object.
A JavaScript Promise or a promise-like object.
A JavaScript string.
A JavaScript Symbol.
Abstract supertype of all JavaScript typed arrays.
A JavaScript Uint16Array.
A JavaScript Uint32Array.
A JavaScript Uint8Array.
A JavaScript Uint8ClampedArray.


BoolToJSBoolean on bool
Conversions from bool to JSBoolean.
ByteBufferToJSArrayBuffer on ByteBuffer
Conversions from ByteBuffer to JSArrayBuffer.
ByteDataToJSDataView on ByteData
Conversions from ByteData to JSDataView.
DoubleToJSNumber on double
Conversions from double to JSNumber.
ExternalDartReferenceToObject on ExternalDartReference
Conversions from ExternalDartReference to Object.
Float32ListToJSFloat32Array on Float32List
Conversions from Float32List to JSFloat32Array.
Float64ListToJSFloat64Array on Float64List
Conversions from Float64List to JSFloat64Array.
FunctionToJSExportedDartFunction on Function
Conversions from Function to JSExportedDartFunction.
FutureOfJSAnyToJSPromise on Future<T>
Conversions from Future to JSPromise where the Future returns a value.
FutureOfVoidToJSPromise on Future<void>
Conversions from Future to JSPromise where the Future does not return a value.
Int16ListToJSInt16Array on Int16List
Conversions from Int16List to JSInt16Array.
Int32ListToJSInt32Array on Int32List
Conversions from Int32List to JSInt32Array.
Int8ListToJSInt8Array on Int8List
Conversions from Int8List to JSInt8Array.
JSAnyOperatorExtension on JSAny?
General-purpose JavaScript operators.
JSAnyUtilityExtension on JSAny?
Common utility functions that are useful for any JavaScript value.
JSArrayBufferToByteBuffer on JSArrayBuffer
Conversions from JSArrayBuffer to ByteBuffer.
JSArrayToList on JSArray<T>
Conversions from JSArray to List.
JSBooleanToBool on JSBoolean
Conversions from JSBoolean to bool.
JSBoxedDartObjectToObject on JSBoxedDartObject
Conversions from JSBoxedDartObject to Object.
JSDataViewToByteData on JSDataView
Conversions from JSDataView to ByteData.
JSExportedDartFunctionToFunction on JSExportedDartFunction
Conversions from JSExportedDartFunction to Function.
JSFloat32ArrayToFloat32List on JSFloat32Array
Conversions from JSFloat32Array to Float32List.
JSFloat64ArrayToFloat64List on JSFloat64Array
Conversions from JSFloat64Array to Float64List.
JSFunctionUtilExtension on JSFunction
Utility extensions for JSFunction.
JSInt16ArrayToInt16List on JSInt16Array
Conversions from JSInt16Array to Int16List.
JSInt32ArrayToInt32List on JSInt32Array
Conversions from JSInt32Array to Int32List.
JSInt8ArrayToInt8List on JSInt8Array
Conversions from JSInt8Array to Int8List.
JSNumberToNumber on JSNumber
Conversions from JSNumber to double or int.
JSPromiseToFuture on JSPromise<T>
Conversions from JSPromise to Future.
JSStringToString on JSString
Conversions from JSString to String.
JSUint16ArrayToInt16List on JSUint16Array
Conversions from JSUint16Array to Uint16List.
JSUint32ArrayToUint32List on JSUint32Array
Conversions from JSUint32Array to Uint32List.
JSUint8ArrayToUint8List on JSUint8Array
Conversions from JSUint8Array to Uint8List.
JSUint8ClampedArrayToUint8ClampedList on JSUint8ClampedArray
Conversions from JSUint8ClampedArray to Uint8ClampedList.
ListToJSArray on List<T>
Conversions from List to JSArray.
NullableObjectUtilExtension on Object?
Common utility functions for Object?s.
NullableUndefineableJSAnyExtension on JSAny?
Helper methods to determine if a value is JavaScript undefined or null.
NumToJSExtension on num
Conversions from num to JSNumber.
ObjectToExternalDartReference on Object
Conversions from Object to ExternalDartReference.
ObjectToJSBoxedDartObject on Object
Conversions from Object to JSBoxedDartObject.
StringToJSString on String
Conversions from String to JSString.
Uint16ListToJSInt16Array on Uint16List
Conversions from Uint16List to JSUint16Array.
Uint32ListToJSUint32Array on Uint32List
Conversions from Uint32List to JSUint32Array.
Uint8ClampedListToJSUint8ClampedArray on Uint8ClampedList
Conversions from Uint8ClampedList to JSUint8ClampedArray.
Uint8ListToJSUint8Array on Uint8List
Conversions from Uint8List to JSUint8Array.


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


globalContext JSObject
The global scope that is used to find user-declared interop members.
no setter


createJSInteropWrapper<T extends Object>(T dartObject) JSObject
Given a instance of a Dart class that contains an @JSExport annotation, creates a JavaScript object that wraps the given Dart object.
importModule(String moduleName) JSPromise<JSObject>
Dynamically imports a JavaScript module with the given moduleName using the JavaScript import() syntax.


JSVoid = void
JS type equivalent for undefined for interop member return types.

Exceptions / Errors

Exception for when the promise is rejected with a null or undefined value.