Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

feat(): Add support for void generic argument, which translates to dynamic #334

Merged
merged 1 commit into from
Feb 4, 2016

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Feb 3, 2016

This allows us to use stuff like:

var x: Promise<void> = new Promise((resolve) => resolve());

Which before was harder because we couldn't use void as a generic type.

@hansl
Copy link
Contributor Author

hansl commented Feb 3, 2016

@vikerman @mprobst I'll be happy to discuss this if you guys have comments/objections/questions.

@@ -76,7 +78,13 @@ export class TranspilerBase {
maybeVisitTypeArguments(n: {typeArguments?: ts.NodeArray<ts.TypeNode>}) {
if (n.typeArguments) {
this.emit('<');
this.visitList(n.typeArguments);
this.visitList(n.typeArguments, ',', (node) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, I think it'd be better to make this code less generic, and only specifically handle the case of a single type argument that's void by just leaving out the type argument.

This code is arguable better by being more generic, but in this case we should be restrictive - we shouldn't support patterns that are going to cause odd APIs for Dart users, when we really only need to support Promise<void> and EventEmitter<void>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -75,6 +75,10 @@ export class TranspilerBase {

maybeVisitTypeArguments(n: {typeArguments?: ts.NodeArray<ts.TypeNode>}) {
if (n.typeArguments) {
// If it's a single type argument `<void>`, ignore it and emit nothing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you mention that this is for e.g. Promise<void>, and link to dart-lang/sdk#2231 (comment) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Will submit.

@mprobst
Copy link
Contributor

mprobst commented Feb 4, 2016

One nit, LGTM otherwise.

@mprobst mprobst self-assigned this Feb 4, 2016
@mprobst mprobst added the LGTM label Feb 4, 2016
@hansl hansl merged commit a560bce into dart-archive:master Feb 4, 2016
@hansl hansl deleted the void-templates branch February 4, 2016 17:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

3 participants