Skip to content

Commit 679a7ec

Browse files
committed
Use the value symbol for decorator purpose only if it is same as typesymbol
Fixes microsoft#13155
1 parent d22b963 commit 679a7ec

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20518,18 +20518,21 @@ namespace ts {
2051820518
function getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind {
2051920519
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
2052020520
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
20521-
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
20522-
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
20523-
return TypeReferenceSerializationKind.Promise;
20524-
}
20525-
20526-
const constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
20527-
if (constructorType && isConstructorType(constructorType)) {
20528-
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
20529-
}
2053020521

2053120522
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
2053220523
const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
20524+
if (valueSymbol && valueSymbol === typeSymbol) {
20525+
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
20526+
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
20527+
return TypeReferenceSerializationKind.Promise;
20528+
}
20529+
20530+
const constructorType = getTypeOfSymbol(valueSymbol);
20531+
if (constructorType && isConstructorType(constructorType)) {
20532+
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
20533+
}
20534+
}
20535+
2053320536
// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
2053420537
if (!typeSymbol) {
2053520538
return TypeReferenceSerializationKind.ObjectType;

tests/baselines/reference/metadataOfEventAlias.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ var SomeClass = (function () {
3333
}());
3434
__decorate([
3535
Input,
36-
__metadata("design:type", event_1.Event)
36+
__metadata("design:type", Object)
3737
], SomeClass.prototype, "event", void 0);
3838
exports.SomeClass = SomeClass;

0 commit comments

Comments
 (0)