question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript Error at `pre` hook?

See original GitHub issue

I have i am trying to implement pre hook. The following code works fine, but it is giving me TS lint error potantially invalid reference access to a class field via this. of a nested function.

@pre<Cat>('save', function (next) {
  this.updatedAt = new Date();
  next();
})

But the above code working though. It updates my updatedaAt field.

I am not sure this is related to this library or typegoose itself. But any help would be appriciated!

Thanks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
JakeAicommented, Feb 2, 2020

@emjimadhu @AlecDusheck @kpfromer I use webstorm and this is what I use

@pre<User>('save', async function(this: DocumentType<User>, next) {})
1reaction
AlecDusheckcommented, Oct 19, 2019

Yeah I think something about the decorator confuses the WebStorm inspector and makes it believe that you don’t have access to this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript throws compilation error in Mongoose pre hook ...
I am looking at example code which is placed inside the users.ts file, inside a User model. userSchema.pre('save', async function( ...
Read more >
Run a TypeScript type check in your pre-commit hook using ...
A great way to prevent TypeScript compilation errors from bringing down your CI pipelines is to introduce a type check before you commit...
Read more >
Git pre-commit hook for Typescript errors - Reddit
I wanted to write a git pre-commit hook to abort a commit if there are errors. From the command line I could just...
Read more >
Create a Pre-commit Git Hook to Check and Fix Your ...
In this post, we will introduce how to create a Git pre-commit hook to check JavaScript/TypeScript code using ESLint, Prettier, lint-staged, and Husky....
Read more >
Pre-Commit Hooks for Pretter and ESLint in TypeScript Projects
Before allowing any commits to occur, format the code with Prettier and check for any ESLint warnings or errors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found