Closed
Description
- Dart SDK Version (
dart --version
)
2.1.0-dev.1.0 (also present in 2.0.0-dev.68.0) - What package(s) from this repo you are using, and the version (i.e.
build_runner 0.7.12
)
build_runner 0.9.2 - What builder(s) you are using (or writing yourself). Try to give a short summary of what they do.
dartdevc, dart2js - Whether you are using Windows, MacOSX, or Linux (if applicable)
Linux - Whether you are using Chrome, Safari, Firefox, Edge (if applicable)
Chrome - Any other packages or constraints we should know about
js 0.6.1+1
Dart2js produces code throwing TypeError
s when using wrapped javascript which is known to return typed arrays. ddc code runs fine. cast
on the output of dart2js fixes the issue, but is somewhat unsatisfying.
Repo demonstrating the issue here (including all code below).
Result of running ddc js:
woof, moo
Result of running dart2js js:
Uncaught Error: TypeError: Closure 'minified:by': type '(minified:F) => String' is not a subtype of type '(dynamic) => String'
farm.js
function Animal(sound) {
this._sound = sound
}
Animal.prototype.hello = function() {
return this._sound;
}
function Farm() {
this._animals = [new Animal('woof'), new Animal('moo')];
}
Farm.prototype.animals = function() {
return this._animals;
}
farm.dart
@JS()
library farm;
import 'package:js/js.dart';
@JS()
class Animal {
external factory Animal(String sound);
external String hello();
}
@JS()
class Farm {
external factory Farm();
external List<Animal> animals();
}
index.dart
import 'farm.dart';
void main() {
var animals = new Farm().animals();
// animals = animals.cast<Animal>(); // fixes errors in dart2js
print(animals.map<String>((a) => a.hello()).join(', '));
}
index.html
<!DOCTYPE html>
<html>
<head>
<script src="./farm.js"></script>
<script defer src="./index.dart.js"></script>
</head>
<body></body>
</html>
Metadata
Metadata
Assignees
Labels
No labels