Repository: babel/babel (TypeScript)

Issue:
[Bug]: TypeScript annotation that contains the name of the annotated class method changes final output
### Input code

[REPL link](https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=true&code_lz=KYDwDg9gTgLgBAYwDYEMDOa4BEUxQI3WDgG8AoOOGKFAOzRQRgEsJaAKCyuAeh7gCSAMyoALYjACeYYnVoQ8LNnHFRiCNnmb0xxAFS0UAW2IQRMcXBMWIAEz1dKfXbTjN4CUXQDmwTKIgAd10rYBtbN0wNIzBmJGBbADo4ACVgQxM4AANqOgYmVlosx15-fGAkILg6CLRgYgDgi1MAVxgwNsQvWl80RJKEFCQkQgQAawAuOHZc-kYlWimAFRo5grYASjgAXgA-OBbaMflA2gAaLi3ybjg1GBaoVwtmPrx8eMTZ_IXOG8p2EBbPaIIYjRhjdi0YDBHAQFZ5eaFAEbDYXG4bADcXAAvmRcUA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Ctypescript&prettier=false&targets=Node-2&version=7.24.0&externalPlugins=&assumptions=%7B%7D)

```ts
export class Database {
  transaction(
    // If the type annotation here contains the *name of the method*
    // then it changes how the method is compiled. Rename `transaction`
    // below and see how the output changes.
    callback: (transaction: Transaction) => unknown,
  ) {
    return this.table.transaction(
      (x) => callback(new DaoTransaction(x)),
    );
  }
}

```


### Current and expected behavior

This is a class method called `transaction` that has a parameter called `callback`, which has the following type annotation
```ts
callback: (transaction: Transaction) => unknown
```
note that the parameter in the TypeScript annotation is called `transaction`, like the name of the method the parameter is defined for. 

The TypeScript annotation **should not affect how the code is compiled** but what I've noticed is that the output is much different **when the annotation contains the name of the method**. When thats the case it outputs:
```js
_proto.transaction = function (_transaction) {
    function transaction(_x) {
      return _transaction.apply(this, arguments);
    }
    transaction.toString = function () {
      return _transaction.toString();
    };
    return transaction;
  }(function (
  // If the type annotation here contains the *name of the method*
  // then it changes how the method is compiled. Rename `transaction`
  // below and see how the output changes.
  callback) {
    return this.table.transaction(function (x) {
      return callback(new DaoTransaction(x));
    });
  });
  ```
  
 but if you were to remove the annotation or rename the parameter like
 ```ts
callback: (t: Transaction) => unknown
```
then the output is much simpler, skipping the wrapping function that writes `toString` for whatever reason
```js
 _proto.transaction = function transaction(
  // If the type annotation here contains the *name of the method*
  // then it changes how the method is compiled. Rename `transaction`
  // below and see how the output changes.
  callback) {
    return this.table.transaction(function (x) {
      return callback(new DaoTransaction(x));
    });
  };
  ```


### Environment

See: the REPL link

### Possible solution

_No response_

### Additional context

_No response_


Hints:
Hey @aweary! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant [Slack community](https://babeljs.slack.com) that typically always has someone willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite.

Patch:
diff --git a/packages/babel-traverse/src/scope/index.ts b/packages/babel-traverse/src/scope/index.ts
--- a/packages/babel-traverse/src/scope/index.ts
+++ b/packages/babel-traverse/src/scope/index.ts
@@ -372,6 +372,9 @@ const collectorVisitor: Visitor<CollectVisitorState> = {
       path.scope.registerBinding("local", path);
     }
   },
+  TSTypeAnnotation(path) {
+    path.skip();
+  },
 };
 
 let uid = 0;


Test patch:
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/input.ts b/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/input.ts
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/input.ts
@@ -0,0 +1,12 @@
+class Database {
+  transaction(
+    // If the type annotation here contains the *name of the method*
+    // then it changes how the method is compiled. Rename `transaction`
+    // below and see how the output changes.
+    callback: (transaction: Transaction) => unknown,
+  ) {
+    return this.table.transaction(
+      (x) => callback(new DaoTransaction(x)),
+    );
+  }
+}
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/options.json b/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/options.json
@@ -0,0 +1,3 @@
+{
+  "plugins": ["transform-classes", "transform-typescript"]
+}
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/output.js b/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/misc/function-name-ts-annotation/output.js
@@ -0,0 +1,17 @@
+let Database = /*#__PURE__*/function () {
+  "use strict";
+
+  function Database() {
+    babelHelpers.classCallCheck(this, Database);
+  }
+  return babelHelpers.createClass(Database, [{
+    key: "transaction",
+    value: function transaction(
+    // If the type annotation here contains the *name of the method*
+    // then it changes how the method is compiled. Rename `transaction`
+    // below and see how the output changes.
+    callback) {
+      return this.table.transaction(x => callback(new DaoTransaction(x)));
+    }
+  }]);
+}();