Closed
Description
Original issue file by @jackd dart-lang/build#1771
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>