When emitting metadata about type, Use object type if the type cant be resolved

This could be true if expression cannot be resolved resulting in error
This commit is contained in:
Sheetal Nandi
2015-08-24 12:07:14 -07:00
parent 979e2bf7c4
commit 3ca08916d4
7 changed files with 216 additions and 0 deletions
+4
View File
@@ -14409,6 +14409,10 @@ namespace ts {
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
let typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true);
// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
if (!typeSymbol) {
return TypeReferenceSerializationKind.ObjectType;
}
let type = getDeclaredTypeOfSymbol(typeSymbol);
if (type === unknownType) {
return TypeReferenceSerializationKind.Unknown;
@@ -0,0 +1,27 @@
tests/cases/compiler/service.ts(1,8): error TS1192: Module '"tests/cases/compiler/db"' has no default export.
==== tests/cases/compiler/db.ts (0 errors) ====
export class db {
public doSomething() {
}
}
==== tests/cases/compiler/service.ts (1 errors) ====
import db from './db'; // error no default export
~~
!!! error TS1192: Module '"tests/cases/compiler/db"' has no default export.
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db;
constructor(db: db.db) {
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
@@ -0,0 +1,51 @@
//// [tests/cases/compiler/decoratorMetadataWithImportDeclarationNameCollision4.ts] ////
//// [db.ts]
export class db {
public doSomething() {
}
}
//// [service.ts]
import db from './db'; // error no default export
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db;
constructor(db: db.db) {
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
//// [db.js]
var db = (function () {
function db() {
}
db.prototype.doSomething = function () {
};
return db;
})();
exports.db = db;
//// [service.js]
var db_1 = require('./db'); // error no default export
function someDecorator(target) {
return target;
}
var MyClass = (function () {
function MyClass(db) {
this.db = db;
this.db.doSomething();
}
MyClass = __decorate([
someDecorator,
__metadata('design:paramtypes', [Object])
], MyClass);
return MyClass;
})();
exports.MyClass = MyClass;
@@ -0,0 +1,30 @@
tests/cases/compiler/service.ts(7,9): error TS2503: Cannot find namespace 'db'.
tests/cases/compiler/service.ts(9,21): error TS2503: Cannot find namespace 'db'.
==== tests/cases/compiler/db.ts (0 errors) ====
export default class db {
public doSomething() {
}
}
==== tests/cases/compiler/service.ts (2 errors) ====
import db from './db';
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db; //error
~~
!!! error TS2503: Cannot find namespace 'db'.
constructor(db: db.db) { // error
~~
!!! error TS2503: Cannot find namespace 'db'.
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
@@ -0,0 +1,52 @@
//// [tests/cases/compiler/decoratorMetadataWithImportDeclarationNameCollision7.ts] ////
//// [db.ts]
export default class db {
public doSomething() {
}
}
//// [service.ts]
import db from './db';
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db; //error
constructor(db: db.db) { // error
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
//// [db.js]
var db = (function () {
function db() {
}
db.prototype.doSomething = function () {
};
return db;
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = db;
//// [service.js]
var db_1 = require('./db');
function someDecorator(target) {
return target;
}
var MyClass = (function () {
function MyClass(db) {
this.db = db;
this.db.doSomething();
}
MyClass = __decorate([
someDecorator,
__metadata('design:paramtypes', [Object])
], MyClass);
return MyClass;
})();
exports.MyClass = MyClass;
@@ -0,0 +1,26 @@
// @noemithelpers: true
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @target: es5
// @module: commonjs
// @filename: db.ts
export class db {
public doSomething() {
}
}
// @filename: service.ts
import db from './db'; // error no default export
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db;
constructor(db: db.db) {
this.db = db;
this.db.doSomething();
}
}
export {MyClass};
@@ -0,0 +1,26 @@
// @noemithelpers: true
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @target: es5
// @module: commonjs
// @filename: db.ts
export default class db {
public doSomething() {
}
}
// @filename: service.ts
import db from './db';
function someDecorator(target) {
return target;
}
@someDecorator
class MyClass {
db: db.db; //error
constructor(db: db.db) { // error
this.db = db;
this.db.doSomething();
}
}
export {MyClass};