Updated typecheck for property, method, and parameter decorators

This commit is contained in:
Ron Buckton
2015-03-24 14:27:36 -07:00
parent 70bd582965
commit e6ccaf0329
2 changed files with 11 additions and 5 deletions

View File

@@ -104,6 +104,7 @@ module ts {
let globalClassDecoratorType: ObjectType;
let globalParameterDecoratorType: ObjectType;
let globalPropertyDecoratorType: ObjectType;
let globalMethodDecoratorType: ObjectType;
let tupleTypes: Map<TupleType> = {};
let unionTypes: Map<UnionType> = {};
@@ -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.

5
src/lib/core.d.ts vendored
View File

@@ -1166,5 +1166,6 @@ interface TypedPropertyDescriptor<T> {
}
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
declare type PropertyDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
declare type ParameterDecorator = (target: Function, parameterIndex: number) => void;
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) => void;