-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Description
TypeScript Version: 3.3.3
Search Terms:
is:issue decorator type method name propertyKey
Code:
this works as expected:
interface SomeTypeMap {
fieldOne: string;
fieldTwo: number;
}
function MethodDecorator<Key extends keyof SomeTypeMap>(
target: SomeClass,
methodName: Key,
descriptor: TypedPopertyDescriptor<(...args: any[]) => SomeTypeMap[Key]>) {
/* some implementation */
}
class SomeClass {
// works fine, as expected
@MethodDecorator
public fieldOne() {
return "";
}
// compiler error, as expected
// since it returns string instead of number
@MethodDecorator
public fieldTwo() {
return "";
}
// compiler error, as expected
// since method name is not a key in SomeTypeMap
@MethodDecorator
public fieldThree() {
return "";
}
}this does not work as expected:
enum Field {
One = "fieldOne"
}
interface SomeTypeMap {
[Field.One]: string;
}
function MethodDecorator<Key extends keyof SomeTypeMap>(
target: SomeClass,
methodName: Key,
descriptor: TypedPopertyDescriptor<(...args: any[]) => SomeTypeMap[Key]>) {
/* some implementation */
}
class SomeClass {
// compiler error, unexpected
@MethodDecorator
public [Field.One]() {
return "";
}
}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 type Field
Playground Link:
can't enable experimental decorators in the playground.
Related Issues:
less related:
#30102
Comments:
Thanks for all your hard work TypeScript team.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.