Sdk: dart2js: type 'UnknownJavaScriptObject' is not a subtype of type 'Change0<DocumentSnapshot0>'

Created on 1 Jun 2018  路  7Comments  路  Source: dart-lang/sdk

Starting from 2.0.0-dev.52.0 (it seems) tests in firebase_functions_interop package started failing when code is compiled with --checked flag by dart2js, giving following error:

TypeError: Instance of 'UnknownJavaScriptObject': type 'UnknownJavaScriptObject' is not a subtype of type 'Change0<DocumentSnapshot0>'
    at wrapException (/user_code/build/node/index.dart.js:1943:17)
    at assertSubtype (/user_code/build/node/index.dart.js:2702:15)
    at DocumentBuilder_onWrite_wrapper.dart.DocumentBuilder_onWrite_wrapper.call$2 (/user_code/build/node/index.dart.js:11964:50)
    at Primitives_applyFunctionWithPositionalArguments (/user_code/build/node/index.dart.js:1883:28)
    at dart._callDartFunctionFast (/user_code/build/node/index.dart.js:11082:14)
    at /user_code/build/node/index.dart.js:11071:18
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
    at next (native)
    at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
    at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)

(One more similar error referencing PlainJavaScriptObject: https://github.com/pulyaevskiy/firebase-functions-interop/issues/23).

I've been trying to investigate it myself but I'm really not sure where to start from.
The Change and DocumentSnapshot classes are both declared as @anonymous in bindings, it seems strange to do a type check on anonymous classes.

Looking for some advice, thanks!

OS: MacOS, Linux(Travis)

dart --version
Dart VM version: 2.0.0-dev.59.0 (Tue May 29 22:11:36 2018 +0200) on "macos_x64"
web-dart2js

Most helpful comment

Basically --checked will go away.

The flag had two purposes: enable Dart1 checks and enable assertions. In Dart2, checks are enabled by default with strong-mode (this is what --preview-dart-2 does now), but assertions are not. You'll need --enable-assertions to get the extra assertions.

All 7 comments

I'll let the Dart2JS team weigh in, but I'm not sure of the value of dart2js --checked going forward.

Either you'll want to use DDC, or just normal Dart2JS (--checked is gone in Dart2).

If dart2js --checked is going away it'd be perfectly fine resolution for me. However with stronger Dart2 type system, if dart2js will also be inserting type checks without --checked option, I'm curious if this will resurface at later point.

For dartdevc, I did attempt to compile and deploy a Firebase function this way, but it currently fails, not able to resolve some file paths (I didn't spend a lot of time on this though as it's not a high priority at this point).

@pulyaevskiy You can try, in the latest dev SDK, dart2js --preview-dart-2. That is the stronger one.

This is great. dart2js --preview-dart-2 actually works (despite of being stronger)! I did find a different issue in regards to strong mode, but that was easy to fix.

I'll leave this issue open. if someone from dart2js team can clarify destiny of --checked option it'd be helpful. But feel free to close if there is nothing to add at this point.

Thanks @matanlurey, really appreciate your help!

Very welcome.

Basically --checked will go away.

The flag had two purposes: enable Dart1 checks and enable assertions. In Dart2, checks are enabled by default with strong-mode (this is what --preview-dart-2 does now), but assertions are not. You'll need --enable-assertions to get the extra assertions.

Perfect, thanks for clarification @sigmundch !
Closing this as resolved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xster picture xster  路  3Comments

sgrekhov picture sgrekhov  路  3Comments

matanlurey picture matanlurey  路  3Comments

jmesserly picture jmesserly  路  3Comments

DartBot picture DartBot  路  3Comments