You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The this.world is marked as error, as supposed to be. But it is actually pretty annoying, because in angular you need to use quite often those component bindings. I know there's the option // @ts-ignore, but that really pollutes the code and makes it less readable.
Yes I think that adding declarations in the constructor is the proper workaround for this issue. When TypeScript sees the MyController class, it cannot know that the class be used with a certain set of bindings.
Any other thoughts on this? Could the angular language service help out here?
Not really, AngularJS (1.x) and Angular (2+) are very different. You could make a language service that specifically squelches errors and augments completions, but that's a bad a idea.
Livio Brunner (@BrunnerLivio) are you using something like Babel, or just targeting ES6 runtimes? If you're using a compiler, you can declare your class properties as so and use the appropriate plugin:
What about a more general solution (not AngularJS specific)? Maybe defining in a JSDoc comment above a Class, which properties get injected into a class.
See #28440 for another example of property tag usage:
/** * @description * A Person * * @class */functionPerson(name){/** * @description * Name of the person * @property {String} */this.name=name;/** * @description * Another Name of the person * @property {String} */this.anotherName=name;/** * @description * Another Name of the person * @property {String} * @name Person#AndEvenMoreNames */}
Activity
mjbvz commentedon May 10, 2017
Yes I think that adding declarations in the constructor is the proper workaround for this issue. When TypeScript sees the
MyControllerclass, it cannot know that the class be used with a certain set of bindings.Mohamed Hegazy (@mhegazy) / Chuck Jazdzewski (@chuckjaz) Any other thoughts on this? Could the angular language service help out here?
DanielRosenwasser commentedon May 10, 2017
Not really, AngularJS (1.x) and Angular (2+) are very different. You could make a language service that specifically squelches errors and augments completions, but that's a bad a idea.
DanielRosenwasser commentedon May 10, 2017
Livio Brunner (@BrunnerLivio) are you using something like Babel, or just targeting ES6 runtimes? If you're using a compiler, you can declare your class properties as so and use the appropriate plugin:
BrunnerLivio commentedon May 10, 2017
Daniel Rosenwasser (@DanielRosenwasser) no, I'm not using Babel, I target a ES6 runtime. But thanks for the tip.
What about a more general solution (not AngularJS specific)? Maybe defining in a JSDoc comment above a Class, which properties get injected into a class.
For Example:
Unfortunately
@injectdoes not exist in JSDoc, but maybe you can use @property. But the definition of Property is not fitting:Maybe other options?
mhegazy commentedon May 10, 2017
@propertywould be the best way to go i would say.[-]ts-check is not convenient when using angular 1.5 component binding injection[/-][+]Support JSDoc `@property`[/+]mjbvz commentedon Nov 9, 2018
See #28440 for another example of property tag usage:
PavloPoliakov commentedon Nov 9, 2018
alright, I'd duplicate my case here:
The example above currently doesn't work, since it "does not see" child methods.
it's not only about
@property, but about supporting jsdocnamepathas well.http://usejsdoc.org/about-namepaths.html
Thanks for creating a great product.
Regards,
jimmywarting commentedon Apr 5, 2022