-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Bug]: TypeScript annotation that contains the name of the annotated class method changes final output #16375
Copy link
Copy link
Closed
Labels
i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
Input code
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
callback: (transaction: Transaction) => unknownnote 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:
_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
callback: (t: Transaction) => unknownthen the output is much simpler, skipping the wrapping function that writes toString for whatever reason
_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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue