Repository navigation
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
If an imported module is unused it will be ignored, which is good (It may exist edge cases where this is bad but that is an other discussion).
import {db} from './db'
console.log('Hello Dexter Morgan');Compiles to:
console.log('Hello Dexter Morgan');(One can of course, import './db' to keep it).
But this becomes a problem if I use emitDecoratorMetadata and a decorator:
import {db} from './db';
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db;
constructor(db: db) {
this.db = db;
this.db.doSomething();
}
}
export {MyClass};This compiles to:
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function someDecorator(target) {
return target;
}
var MyClass = (function () {
function MyClass(db) {
this.db = db;
this.db.doSomething();
}
MyClass = __decorate([
someDecorator,
__metadata('design:paramtypes', [db_1.db]) // db_1 is not defined
], MyClass);
return MyClass;
})();
exports.MyClass = MyClass;And if a run this code I get ReferenceError: db_1 is not defined.
The funny thing is however that this code works:
import {db as Database} from './db';
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: Database;
constructor(db: Database) {
this.db = db;
this.db.doSomething();
}
}
export {MyClass}If I import the database class with import {Database} from './db'; it works as well. So it seams like the compiler ignore to import a module if its name is in lower case?
I'm using version 1.6.0-dev.20150808 of tsc.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Activity
[-]Require been ignord for emitDecoratorMetadata if lowercase[/-][+]Require been ignord for emitDecoratorMetadata if module is unused and name is lowercase[/+]sheetalkamat commentedon Aug 20, 2015
Oskar Karlsson (@tjoskar) :
Understood the issue here. When trying to resolve db as value because we are going to reference parameter type, db is resolved to parameter named db instead of the import alias named db. I am working on the fix. Thanks for reporting the issue.
Resolve the decorator type as type and check if the symbol has value.
Tests for #4239
mhegazy commentedon Aug 24, 2015
Oskar Karlsson (@tjoskar) sorry for the delay. can you give
typescript@nexta try tonight and see if this emits the correct code now.tjoskar commentedon Aug 25, 2015
Thanks for looking into the issue.
I just upgraded
tsdto the latest version:But the issue remande. I may however wait a few more hours for
Version 1.6.0-dev.20150825. Time zones can be a problem sometimes.mhegazy commentedon Aug 25, 2015
Oskar Karlsson (@tjoskar),
1.6.0-dev.20150825is the one with the fix.