Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dart2js TypeErrors on typed javascript-wrapped arrays #1771

Closed
6 tasks
jackd opened this issue Aug 19, 2018 · 1 comment
Closed
6 tasks

dart2js TypeErrors on typed javascript-wrapped arrays #1771

jackd opened this issue Aug 19, 2018 · 1 comment

Comments

@jackd
Copy link

jackd commented Aug 19, 2018

  • 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 TypeErrors 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>
@jakemac53
Copy link
Contributor

Thanks for the nice repro case - I think this is a general dart2js or package:js issue so I moved it to dart-lang/sdk#34195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants