Skip to content

Use of decorator factories as decorators is not flagged as an error #3246

Description

@mhegazy

As mentioned in #2249 (comment), consider this:

// decorator factory
function F(options?: {optional: boolean}) {
     // returns a property decorator
    return (target , propertyKey): void => {
        // decorator implementation
    }
}

class C {
    @F()    // OK, used as a factory
    prop1; 

    @F   // No error
    prop2; 
}

The problem here is that the compiler compares the signature of the decorator factory F against declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void; which ends up to be assignable. I think we need a stronger check here to make sure we catch these issue.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions