Open
Description
The set of reserved keywords in JS isn't exactly the same as in Dart, and numerous keywords that aren't allowed as instance member names in Dart are allowed in JS. This means that JS APIs not-infrequently use these names for options objects. The name default
in particular is a keyword in Dart and a likely option in JS APIs.
Currently, Dart's JS interop can't easily construct options objects that use these keyword-style option names. I'd expect the following to work:
@anonymous
extension type KeywordBag._(JSObject _) implements JSObject {
external KeywordBag({JSAny? defaultValue});
@JS('default')
external JSAny? get defaultValue;
}
But this example demonstrates that the object is actually constructed with a field named defaultValue
, not default
, despite the @JS
annotation:
import 'dart:js_interop';
@JS('Object.getOwnPropertyNames')
external JSArray<JSString> getOwnPropertyNames(JSObject object);
@anonymous
extension type KeywordBag._(JSObject _) implements JSObject {
external KeywordBag({JSAny? defaultValue});
@JS('default')
external JSAny? get defaultValue;
}
void main() {
print(getOwnPropertyNames(KeywordBag(defaultValue: 123.toJS)));
}