dart-archive / ts2dart

ts2dart TypeScript to Dart transpiler
Apache License 2.0
181 stars 62 forks source link

Type information lost in named parameter list (part 2) #361

Closed mhevery closed 8 years ago

mhevery commented 8 years ago

Given:

RouteDefinition {
  name: string;
}
class AbstractRoute {
  constructor({name}: RouteDefinition) {}
}

Expected:

class AbstractRoute {
  AbstractRoute({String name}) {}
}

Was:

class AbstractRoute {
  AbstractRoute({name}) {}
}
mhevery commented 8 years ago

Also fails in this case: Given:

interface RegexSerializer { (params: {[key: string]: any}): GeneratedUrl; }
interface RouteDefinition {
  serializer?: RegexSerializer;
}

Expected:

typedef GeneratedUrl RegexSerializer(Map<String, dynamic> params);
abstract class RouteDefinition {
  final RegexSerializer serializer; // <<<<< Expected change
  const RouteDefinition({this.serializer});
}

Actual:

typedef GeneratedUrl RegexSerializer(Map<String, dynamic> params);
abstract class RouteDefinition {
  final Function serializer; // <<<< Issue
  const RouteDefinition({this.serializer});
}
mprobst commented 8 years ago

The first example is tricky in the general case. You're asking to correlate the left hand side property 'name' with the property definition of the same name in the rhs type. I'll have to take a look at the available APIs.

The lost property type with the regexserializer is a separate issue.

Miško Hevery notifications@github.com schrieb am Mo., 4. Apr. 2016, 20:49:

Also fails in this case: Given:

interface RegexSerializer { (params: {[key: string]: any}): GeneratedUrl; } interface RouteDefinition { serializer?: RegexSerializer; }

Expected:

typedef GeneratedUrl RegexSerializer(Map<String, dynamic> params); abstract class RouteDefinition { final RegexSerializer serializer; // <<<<< Expected change const RouteDefinition({this.serializer}); }

Actual:

typedef GeneratedUrl RegexSerializer(Map<String, dynamic> params); abstract class RouteDefinition { final Function serializer; const RouteDefinition({this.serializer}); }

— You are receiving this because you were assigned.

Reply to this email directly or view it on GitHub https://github.com/angular/ts2dart/issues/361#issuecomment-205444546

mhevery commented 8 years ago

Any update?

mprobst commented 8 years ago

I cannot reproduce the final Function serializer; issue, see https://reviews.angular.io/D56.

Will take a look at the RouteDefinition destructuring next.

mprobst commented 8 years ago

This should be fixed.