diff --git a/can-define.js b/can-define.js index 1082858..9098a53 100644 --- a/can-define.js +++ b/can-define.js @@ -182,6 +182,17 @@ define.property = function(objPrototype, prop, definition, dataInitializers, com var type = definition.type; + //!steal-remove-start + if (type && canReflect.isConstructorLike(type)) { + dev.warn( + "can-define: the definition for " + + prop + + (objPrototype.constructor.shortName ? " on " + objPrototype.constructor.shortName : "") + + " uses a constructor for \"type\". Did you mean \"Type\"?" + ); + } + //!steal-remove-end + // Special case definitions that have only `type: "*"`. if (type && onlyType(definition) && type === define.types["*"]) { Object.defineProperty(objPrototype, prop, { diff --git a/define-test.js b/define-test.js index 2d94fc4..e04de66 100644 --- a/define-test.js +++ b/define-test.js @@ -5,6 +5,7 @@ var CanList = require("can-define/list/list"); var canBatch = require("can-event/batch/batch"); var each = require("can-util/js/each/each"); var canSymbol = require("can-symbol"); +var canDev = require("can-util/js/dev/dev"); QUnit.module("can-define"); @@ -1368,3 +1369,45 @@ QUnit.test('define() should add a CID (#246)', function() { var g = new Greeting(); QUnit.ok(g._cid, "should have a CID property"); }); + +if (System.env.indexOf("production") < 0) { + + QUnit.test("warn on using a Constructor for small-t type definintions", function() { + expect(2); + var oldWarn = canDev.warn; + canDev.warn = function(mesg) { + QUnit.equal(mesg, "can-define: the definition for currency uses a constructor for \"type\". Did you mean \"Type\"?"); + }; + + function Currency() { + return this; + } + Currency.prototype = { + symbol: "USD" + }; + + function VM() {} + define(VM.prototype, { + currency: { + type: Currency, // should be `Type: Currency` + value: new Currency({}) + } + }); + + canDev.warn = function(mesg) { + QUnit.equal(mesg, "can-define: the definition for currency on VM2 uses a constructor for \"type\". Did you mean \"Type\"?"); + }; + + function VM2() {} + VM2.shortName = "VM2"; + define(VM2.prototype, { + currency: { + type: Currency, // should be `Type: Currency` + value: new Currency({}) + } + }); + + canDev.warn = oldWarn; + }); + +} \ No newline at end of file