Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support decorators on function declarations #4824

Closed
SergioMorchon opened this issue Sep 16, 2015 · 4 comments
Closed

Support decorators on function declarations #4824

SergioMorchon opened this issue Sep 16, 2015 · 4 comments
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@SergioMorchon
Copy link

Hi all.

I think it would be a great feature if we can use decorators with functions too.

Example

// SImple use case
function deprecated(target: Function) {
    let oldFunction = target;
    return (...args) {
        console.log("You are using a deprecated function").
        return oldFunction.apply(null, args);
    };
}

@deprecated
function legacy(...args) {/* ... */};

It also would enable patterns like Contract, with pre/post conditions checks etc.

@SergioMorchon SergioMorchon changed the title Decorators on functions Proposal: Decorators on functions Sep 16, 2015
@DanielRosenwasser
Copy link
Member

Hi @SergioMorchon, thanks for the suggestion. Functions are hoisted, so what are the intended semantics? See the conversation at #2249 (comment).

That's the main problem, and the ECMA-262 committee doesn't seem totally sure what to do about it either. We'd need more details, so this is a suggestion at this point, not a proposal. See our guide on writing good design proposals.

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Sep 16, 2015
@DanielRosenwasser DanielRosenwasser changed the title Proposal: Decorators on functions Suggestion: Decorators on function declarations Sep 16, 2015
@DanielRosenwasser DanielRosenwasser changed the title Suggestion: Decorators on function declarations Support decorators on function declarations Sep 16, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Sep 16, 2015

Any thing that typescript will support in this domain needs to be inline with the ES proposal. see wycats/javascript-decorators#31 for related discussion.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 16, 2015

The JS-decorator proposal is the right place to have this discussion. Please submit the proposal on https://github.com/wycats/javascript-decorators repo instead.

@mhegazy mhegazy closed this as completed Sep 16, 2015
@mhegazy mhegazy added the Out of Scope This idea sits outside of the TypeScript language design constraints label Sep 16, 2015
@SergioMorchon
Copy link
Author

@mhegazy definitely agree, thank you for the info!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants