mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
Updated typecheck for property, method, and parameter decorators
This commit is contained in:
@@ -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
5
src/lib/core.d.ts
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user