Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

No best common type exists among return expressions #313

Closed hongbo-miao closed 8 years ago

hongbo-miao commented 8 years ago

When I use try the code in the example in angular2-meteor,

createdAt: {
    type: Date,
    autoValue: function() {
      if (this.isInsert) {
        return new Date();
      } else if (this.isUpsert) {
        return {$setOnInsert: new Date()};
      } else {
        this.unset();
      }
    }
  }

it will give the warning:

No best common type exists among return expressions.

How about changing to this?

createdAt: {
    type: Date,
    autoValue: function() {
      if (this.isInsert) {
        return new Date();
      } else if (this.isUpsert) {
        return {$setOnInsert: new Date()};
      } else {
        this.unset();
        return undefined;  // <- add this line
      }
    }
  }
hongbo-miao commented 8 years ago

It is related with TypeScript, this is not correct way to avoid the warning. I need more time to confirm

hongbo-miao commented 8 years ago

Oh, I got solution here.