You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceSomeTypeMap{fieldOne: string;fieldTwo: number;}functionMethodDecorator<KeyextendskeyofSomeTypeMap>(target: SomeClass,methodName: Key,descriptor: TypedPopertyDescriptor<(...args: any[])=>SomeTypeMap[Key]>){/* some implementation */}classSomeClass{// works fine, as expected
@MethodDecoratorpublicfieldOne(){return"";}// compiler error, as expected// since it returns string instead of number
@MethodDecoratorpublicfieldTwo(){return"";}// compiler error, as expected// since method name is not a key in SomeTypeMap
@MethodDecoratorpublicfieldThree(){return"";}}
namespaceField{exportconstOne=Symbol("something")exportconstTwo=Symbol("another thing")}interfaceSomeTypeMap{[Field.One]: string;[Field.Two]: number;}functionMethodDecorator<KeyextendskeyofSomeTypeMap>(target: SomeClass,methodName: Key,descriptor: TypedPopertyDescriptor<(...args: any[])=>SomeTypeMap[Key]>){/* some implementation */}classSomeClass{// works fine, as expected
@MethodDecoratorpublic[Field.One](){return"";}// compiler error, as expected// since it returns string instead of number
@MethodDecoratorpublic[Field.Two](){return"";}}
TypeScript Version: 3.3.3
Search Terms:
is:issue decorator type method name propertyKey
Code:
this works as expected:
this does not work as expected:
Expected behavior:
In the second code example, I would expect there to be no compiler errors.
Actual behavior:
Error message:
Argument of type 'string' is not assignable to parameter of type Field
The method name seems to be of type
string
here, which is true, but it should also be of typeField
Playground Link:
can't enable experimental decorators in the playground.
Related Issues:
#17795
less related:
#30102
Comments:
Thanks for all your hard work TypeScript team.
The text was updated successfully, but these errors were encountered: