Skip to content

Use unknown serialization kind when type symbol isnt resolved #24332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26667,7 +26667,7 @@ namespace ts {

// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
if (!typeSymbol) {
return TypeReferenceSerializationKind.ObjectType;
return TypeReferenceSerializationKind.Unknown;
}
const type = getDeclaredTypeOfSymbol(typeSymbol);
if (type === unknownType) {
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,8 @@ namespace ts {
* @param node The type reference node.
*/
function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode {
switch (resolver.getTypeReferenceSerializationKind(node.typeName, currentScope)) {
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentScope);
switch (kind) {
case TypeReferenceSerializationKind.Unknown:
const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true);
const temp = createTempVariable(hoistVariableDeclaration);
Expand Down Expand Up @@ -2006,8 +2007,9 @@ namespace ts {
return createIdentifier("Promise");

case TypeReferenceSerializationKind.ObjectType:
default:
return createIdentifier("Object");
default:
return Debug.assertNever(kind);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.
tests/cases/compiler/decoratorMetadataNoLibIsolatedModulesTypes.ts(2,6): error TS2304: Cannot find name 'Decorate'.
tests/cases/compiler/decoratorMetadataNoLibIsolatedModulesTypes.ts(3,13): error TS2304: Cannot find name 'Map'.


!!! error TS2318: Cannot find global type 'Array'.
!!! error TS2318: Cannot find global type 'Boolean'.
!!! error TS2318: Cannot find global type 'Function'.
!!! error TS2318: Cannot find global type 'IArguments'.
!!! error TS2318: Cannot find global type 'Number'.
!!! error TS2318: Cannot find global type 'Object'.
!!! error TS2318: Cannot find global type 'RegExp'.
!!! error TS2318: Cannot find global type 'String'.
==== tests/cases/compiler/decoratorMetadataNoLibIsolatedModulesTypes.ts (2 errors) ====
export class B {
@Decorate
~~~~~~~~
!!! error TS2304: Cannot find name 'Decorate'.
member: Map<string, number>;
~~~
!!! error TS2304: Cannot find name 'Map'.
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [decoratorMetadataNoLibIsolatedModulesTypes.ts]
export class B {
@Decorate
member: Map<string, number>;
}


//// [decoratorMetadataNoLibIsolatedModulesTypes.js]
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
exports.__esModule = true;
var B = /** @class */ (function () {
function B() {
}
var _a;
__decorate([
Decorate,
__metadata("design:type", typeof (_a = typeof Map !== "undefined" && Map) === "function" && _a || Object)
], B.prototype, "member");
return B;
}());
exports.B = B;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/decoratorMetadataNoLibIsolatedModulesTypes.ts ===
export class B {
>B : Symbol(B, Decl(decoratorMetadataNoLibIsolatedModulesTypes.ts, 0, 0))

@Decorate
member: Map<string, number>;
>member : Symbol(B.member, Decl(decoratorMetadataNoLibIsolatedModulesTypes.ts, 0, 16))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/decoratorMetadataNoLibIsolatedModulesTypes.ts ===
export class B {
>B : B

@Decorate
>Decorate : any

member: Map<string, number>;
>member : any
>Map : No type information available!
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ var MyClass = /** @class */ (function () {
this.db = db;
this.db.doSomething();
}
var _a;
MyClass = __decorate([
someDecorator,
__metadata("design:paramtypes", [Object])
__metadata("design:paramtypes", [typeof (_a = (typeof db_1.default !== "undefined" && db_1.default).db) === "function" && _a || Object])
], MyClass);
return MyClass;
}());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @noLib: true
// @isolatedModules: true

export class B {
@Decorate
member: Map<string, number>;
}