as<T extends JSObject> method
T?
as<T extends JSObject>()
Casts this JSObject to T, returning null if it isn't a T.
The JS type of T is only checked when it can be told apart at runtime.
With dart2wasm no interop type can, and with dart2js types erased to
the same runtime type as JSObject (e.g. JSPromise) can't, so in
those cases this only casts. Prefer isA<T>() with a concrete type
argument when the check matters.
Implementation
T? as<T extends JSObject>() {
if (isUndefinedOrNull) return null;
if (_interopTypesErased || T == JSObject) {
return this as T;
} else if (T == JSArray) {
return isA<JSArray>() ? this as T : null;
} else if (T == JSArrayBuffer) {
return isA<JSArrayBuffer>() ? this as T : null;
} else if (T == JSTypedArray) {
return isA<JSTypedArray>() ? this as T : null;
} else if (T == JSInt8Array) {
return isA<JSInt8Array>() ? this as T : null;
} else if (T == JSUint8Array) {
return isA<JSUint8Array>() ? this as T : null;
} else if (T == JSUint8ClampedArray) {
return isA<JSUint8ClampedArray>() ? this as T : null;
} else if (T == JSInt16Array) {
return isA<JSInt16Array>() ? this as T : null;
} else if (T == JSUint16Array) {
return isA<JSUint16Array>() ? this as T : null;
} else if (T == JSInt32Array) {
return isA<JSInt32Array>() ? this as T : null;
} else if (T == JSUint32Array) {
return isA<JSUint32Array>() ? this as T : null;
} else if (T == JSFloat32Array) {
return isA<JSFloat32Array>() ? this as T : null;
} else if (T == JSFloat64Array) {
return isA<JSFloat64Array>() ? this as T : null;
} else if (T == JSDataView) {
return isA<JSDataView>() ? this as T : null;
} else if (T == JSFunction) {
return isA<JSFunction>() ? this as T : null;
} else {
try {
return this as T;
} catch (_) {
return null;
}
}
}