Repository: TypeScript
Issue: Suggestion: ClassMethodDecoratorContext's name property could pick up Value["name"]
Labels: Needs More Info

# lib Update Request

## Configuration Check

My compilation *target* is `ESNext` and my *lib* is `the default`.

## Missing / Incorrect Definition

```typescript
interface ClassMethodDecoratorContext<
    This = unknown,
    Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
> {
    // ...
    /** The name of the decorated class element. */
    readonly name: string | symbol;

    // ...
```

We could change the `name` field to: `readonly name: Value extends { name: string } ? Value["name"] : (string | symbol);`.  Most of the time, Value["name"] is just `string`, so this would be a non-breaking change (if slightly less intuitive).

_However_, if I were to augment my method type definitions to have a name property, TypeScript could pick up on it:

## Sample Code
```typescript
export type NumberStringType = {
    repeatForward(s: string, n: number): string;
    repeatBack(n: number, s: string): string;
};

type NST_RF_raw = NumberStringType["repeatForward"]["name"]
//   ^? type NST_RF_raw = string

type MethodsOnlyType = {
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
  [key: string | number | symbol]: (...args: any[]) => any
}

type NamedMethodsOnlyType<T extends MethodsOnlyType> = {
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
  [Key in keyof T]: T[Key] & { name: Key }
}

type NST_RF_named = NamedMethodsOnlyType<NumberStringType>["repeatForward"]["name"];
//   ^? type NST_RF_named = "repeatForward"

type DefaultInferredName = ClassMethodDecoratorContext<
//   ^? type DefaultInferredName = string | symbol
  NumberStringType, NamedMethodsOnlyType<NumberStringType>["repeatForward"]
>["name"];

interface ClassMethodDecoratorContext_Named<
  This = unknown,
  Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
> {
  readonly name: Value extends { name: string } ? Value["name"] : (string | symbol);
}

type DirectName = ClassMethodDecoratorContext_Named<
//   ^? type Directname = "repeatForward"
  NumberStringType, NamedMethodsOnlyType<NumberStringType>["repeatForward"]
>["name"];

type InferredName = ClassMethodDecoratorContext_Named<
//   ^? type InferredName = string
  NumberStringType, NumberStringType["repeatForward"]
>["name"];
```

[Obligatory Playground link](https://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ation

[I've been experimenting with method decorators](https://github.com/ajvincent/es-membrane/tree/dc226645f250ecd8fb365f3bdfb59f1402b9a4de/_03c_aspects_decorators/spec/methods) for about a week now, to implement some aspect-oriented programming (or at least, my understanding of it).  One facet I haven't yet cracked is removing the need for the method name on a decorator:

```typescript
  class NST_Class extends NumberStringClass {
    @precondition<"repeatForward">(callForwardPre)
    repeatForward(s: string, n: number): string {
      return super.repeatForward(s, n);
    }
  }
```

Since the context has a name field of `string | symbol` type, I can't infer the name from that... I think.

I am perfectly willing to be wrong and have this whole ticket closed as invalid!

## Documentation Link

The ECMAScript 2023 specification [for Function.name](https://262.ecma-international.org/14.0/#sec-function-instances-name) says I'm possibly wrong here: it specifies the `name` field must be a string (specifically, "not a symbol").  This could be just a specification bug with the introduction of symbol keys, but I am not ready to assert that at this time.