TypeScript/tests/cases/compiler/decoratorMetadataGenericTypeVariable.ts
Martin Probst 55c3ec3e94 Fix decorator design:types emit for type variables.
Previously, TypeScript would resolve the reified types for the
`design:types` decorator emit in the regular `currentScope`. That scope
does not include class declaration bodies.

However when reifying types, class declarations do introduce a new scope
for any `TypeVariable`s declared on them. Because TS resolved the
EntityName for such types against the parent scope (e.g. the source
file), not the class scope, TypeScript would either fail to resolve the type (giving `TypeReferenceSerializationKind.Unknown`), or
incorrectly resolve to a different, accidentally matching symbol in the outer scope (giving `TypeWithConstructSignatureAndValue`).

This would result in an emit referencing an undeclared symbol, or
mis-referencing the wrong symbol.

    __metadata("design:type", typeof (_a = typeof TypeVariable !== "undefined" && TypeVariable) === "function" && _a || Object)
    __metadata("design:type", TypeVariable)

This change special cases `currentScope` for
`serializeTypeReferenceNode` to use a class scope, if present. This
changes the emit for a `TypeVariable` back to `Object`:

    __metadata("design:type", Object)
2018-06-25 17:24:05 +02:00

8 lines
135 B
TypeScript

// @experimentalDecorators: true
// @emitDecoratorMetadata: true
export class C<TypeVariable> {
@Decorate
member: TypeVariable;
}