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.

Request: Class Decorator Mutation

See original GitHub issue

If we can get this to type check properly, we would have perfect support for boilerplate-free mixins:

declare function Blah<T>(target: T): T & {foo: number}

class Foo {
    bar() {
        return; // Property 'foo' does not exist on type 'Foo'

new Foo().foo; // Property 'foo' does not exist on type 'Foo'

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1094
  • Comments:242 (53 by maintainers)

github_iconTop GitHub Comments

g162h3commented, Sep 21, 2015

Same would be useful for methods:

class Foo {
  bar(x: number) {
    return x || Promise.resolve(...);

The async decorator is supposed to change the return type to Promise<any>.

masaeeducommented, Feb 23, 2016

If the primary benefit of this is introducing additional members to the type signature, you can already do that with interface merging:

interface Foo { foo(): number }
class Foo {
    bar() {
} = function() { return 10; }

new Foo().foo();

If the decorator is an actual function that the compiler needs to invoke in order to imperatively mutate the class, this doesn’t seem like an idiomatic thing to do in a type safe language, IMHO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Instancing class with an without new with a class decorator
Unfortunately, decorators don't mutate the types of the things they decorate in TypeScript. That means the Someone constructor will not be ...
Read more >
Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use...
Read more >
Top 5 vuex-module-decorators Code Examples - Snyk
Learn more about how to use vuex-module-decorators, based on vuex-module-decorators code examples created from the most popular ways it is used in public ......
Read more >
GraphQl-Decorator - GitHub Pages
GraphQl-Decorator · Model class to define how the schema will be. · Resolver class to create query/mutations. · A function defined by you...
Read more >
Resolvers - TypeGraphQL
After that we can use the AddRecipeInput type in our mutation. We can do this inline (using @Arg() decorator) or as a field...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found