From e6ccaf0329b5cfd4d0553fe10557e5a31b164e93 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 24 Mar 2015 14:27:36 -0700 Subject: [PATCH] Updated typecheck for property, method, and parameter decorators --- src/compiler/checker.ts | 11 ++++++++--- src/lib/core.d.ts | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2429151005f..fec3ff69385 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -104,6 +104,7 @@ module ts { let globalClassDecoratorType: ObjectType; let globalParameterDecoratorType: ObjectType; let globalPropertyDecoratorType: ObjectType; + let globalMethodDecoratorType: ObjectType; let tupleTypes: Map = {}; let unionTypes: Map = {}; @@ -8530,12 +8531,15 @@ module ts { break; case SyntaxKind.PropertyDeclaration: + checkTypeAssignableTo(exprType, globalPropertyDecoratorType, node); + break; + case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - let propertyType = getTypeOfNode(node.parent); - let propertyDecoratorType = instantiateSingleCallFunctionType(globalPropertyDecoratorType, [propertyType]); - checkTypeAssignableTo(exprType, propertyDecoratorType, node); + let methodType = getTypeOfNode(node.parent); + let methodDecoratorType = instantiateSingleCallFunctionType(globalMethodDecoratorType, [methodType]); + checkTypeAssignableTo(exprType, methodDecoratorType, node); break; case SyntaxKind.Parameter: @@ -11343,6 +11347,7 @@ module ts { globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1); globalClassDecoratorType = getGlobalType("ClassDecorator"); globalPropertyDecoratorType = getGlobalType("PropertyDecorator"); + globalMethodDecoratorType = getGlobalType("MethodDecorator"); globalParameterDecoratorType = getGlobalType("ParameterDecorator"); // If we're in ES6 mode, load the TemplateStringsArray. diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 9123c3840c4..2096fa839df 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1166,5 +1166,6 @@ interface TypedPropertyDescriptor { } declare type ClassDecorator = (target: TFunction) => TFunction | void; -declare type PropertyDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; -declare type ParameterDecorator = (target: Function, parameterIndex: number) => void; +declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void; +declare type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; +declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) => void;