[Feature Request] dart:js_interop
needs isJSAny
and isJSObject
for real-world use cases.
#59932
Labels
area-web
Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.
triage-automation
See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.
type-enhancement
A request for a change that isn't a bug
web-js-interop
Issues that impact all js interop
Currently,
dart:js_interop
only providesisA
from the JSAnyUtilityExtension to check for an extension type in the "JS world."While migrating from
dart:html
to theweb
package, we encountered issues in real-world use cases.The main problem arises when a "JS" instance (
JSAny
) is assigned to a variable of typeObject
. There's currently no official or secure way to cast anObject
back to aJSAny
. Technically, it is prohibitive to handle a JS type asObject
because, once treated as anObject
, you cannot safely cast it back toJSAny
without risking a casting exception, invalid behavior, or even an invalid Wasm cast.To address this, it would be helpful to have the following extension, with the correct implementation provided based on the platform (JS or Wasm):
This would enable developers to correctly check if an
Object
is aJSAny
orJSObject
before attempting a cast.isJSObject
is also included because, in most cases,isA
is used to check for a class type rather than a primitive type.NOTE: After discussing this issue with other developers, we concluded that without a secure way to cast
Object
toJSAny
, the newdart:js_interop
is not stable for real-world use cases.The text was updated successfully, but these errors were encountered: