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

Generated *.d.ts files lose decorator information #22980

Closed
mendrik opened this issue Mar 29, 2018 · 2 comments
Closed

Generated *.d.ts files lose decorator information #22980

mendrik opened this issue Mar 29, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@mendrik
Copy link

mendrik commented Mar 29, 2018

When writing a library that relies heavily on decorators in typescript, it would be beneficial if decorator information could be somehow preserved in the generated *.d.t.s file. I don't have any suggestion how it could be done except for maybe just code comments containing the original decorator.

Currently code like this

module feather.ui {

    import Construct = feather.annotations.Construct
    import Widget    = feather.core.Widget
    import deepValue = feather.objects.deepValue
    import TypedMap  = feather.types.TypedMap

    @Construct({selector: 'localization', singleton: true, attributes: ['translations']})
    export class Localization extends Widget {

        translations: TypedMap<any> = {}

        constructor(translations: TypedMap<any>) {
            super()
            this.translations = translations
        }

        translate = (key: string) =>
            deepValue(this.translations, key) || key
    }
}

could generate this:

declare module feather.ui {
    import Widget = feather.core.Widget;
    import TypedMap = feather.types.TypedMap;
    /* @Construct({selector: 'localization', singleton: true, attributes: ['translations']}) */
    class Localization extends Widget {
        translations: TypedMap<any>;
        constructor(translations: TypedMap<any>);
        translate: (key: string) => any;
    }
}

Since I'm writing a IDE plugin, I could read that comment to help me with looking up methods that satisfy particular criteria in a published library.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 29, 2018

Decorators as they stand today have no impact on the type. they are more of an implementation detail if you may. thus keeping them in the declaration file is not correct. moreover, a decorator depends on expressions, e.g. @Construct( myVariable ) having that in your declaration file is a bit meaningless, since the value of myVariable is known only at runtime.

We do have a proposal for a design-time decorator, that acts more like comments in this case, and these would be trafficked to the generated .d.ts, see more in #2900

@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 29, 2018
@mendrik
Copy link
Author

mendrik commented Mar 29, 2018

thank you for your answer, I'll close this as you are right about the runtime aspect, which I didn't think through.

@mendrik mendrik closed this as completed Mar 29, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants