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.

Add a @Deprecated decorator for deprecation warnings

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

At the moment there is no normalized way to add a deprecation warning of a functionality

Expected behavior

There should be a @Depreacted(message?: string) decorator which logs a deprecation warning when calling the function.

E.g.

class MyService {
  
  @Deprecrated('The noGood method will be deprecated in the next major release. Please use the reallyGood method of the MyService instance')
  public noGood() {
    // my super old function
    console.log('No good :(');
  }

  public reallyGood() {
    console.log('Wow this function is so much nicer');
  }
}

[...]

this.myService.noGood(); 

// prints out:
// Deprecation warning: The noGood method will be deprecated in the next major release. Please use the reallyGood method of the MyService instance
// No good :(

What is the motivation / use case for changing the behavior?

It would be useful for a developer to add a clear deprecation warning for a function. This can also be useful for NestJS or its additional modules.

I think it should be part of Nest, so it can be integrated with the already existing logger.

Other

Deprecating before runtime (Intelisense) is currently not possible with TypeScript. See issue here https://github.com/Microsoft/TypeScript/issues/390

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
lazarljubenoviccommented, Nov 7, 2018

I’d expect @Deprecated as a decorator on a controller method to include deprecation warning in the Response, not the log it. Like, deprecating an API method (endpoint), not a method from code. For deprecating methods, TSDoc’s /** @deprecated */ is an already established way. Although, I agree, not runtime-specific – but then again why would Nest provide a runrime deprecation warning for a custom method in code? It seems like a job for a completely separate general TypeScript decorator (there’s probably something on npm already).

One of the ideas is to use 299 code for a deprecated endpoint, which could be what this decorator would do by default.

1reaction
BrunnerLiviocommented, Nov 7, 2018

@lazarljubenovic I see you point, I think you’re right. Looking through the source code of NestJS it seems like it is used by deprecated npm package. The only downside is with this approach, the package is probably not integrated with the NestJS logger, so it will be harder for the user to suppress such warnings. But that is a different topic. I’ll close this issue now. I encourage you (@lazarljubenovic) to create a new issue for controller deprecation functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

decorators in the python standard lib (@deprecated specifically)
deprecation is a library that enables automated deprecations. It offers the deprecated() decorator to wrap functions, providing proper warnings both in ...
Read more >
deprecation — deprecation 2.0.6 documentation
deprecation is a library that enables automated deprecations. It offers the deprecated() decorator to wrap functions, providing proper warnings both in ...
Read more >
Deprecated - PyPI
Python @deprecated decorator to deprecate old python classes, functions or methods.
Read more >
Python deprecation - DEV Community ‍ ‍
To warn about deprecation, you need to set Python's builtin DeprecationWarning as category. To let the warning refer to the caller, so you...
Read more >
Make deprecation highlighting for decorated functions with ...
That's be very cool if I created @deprecated("message") decorator, ... def my_func(): warnings.warn('This function is deprecated', DeprecationWarning).
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