google / google/gts

Unable to declare type of "this" in function

Open
#564 0 comments 0 reactions 0 assignees View on GitHub
priority: p3 type: feature request
Dominant language
TypeScript
Stars
5.3k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

Right now the style rules make it impossible to declare the type of "this" in a function.
When you do it like this:

```typescript
function (this: UserDocument) {
}
```
it tells you to use an arrow function (Unexpected function expression.(prefer-arrow-callback)) that do not support to set "this".

I need this for mongoose virtuals where you can set virtual fields to the value returned by a callback function. You can access all document fields from "this" inside the function. In my use case, there is a virtual field named "makeJwt" which needs access to the jwtSecret stored in the UserDocument.

Is it intended to disallow this in functions in general?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.