-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Salsa - Type discovering for angularjs 1 js controllers #9600
Comments
This is a feature I strongly desire. Please remedy this soon! |
@githop, have you checked the related issue in vscode project? |
@githop unfortunately the problem here seems to be that VSCode itself no longer supports Typings as fully as it did a few weeks ago, after a recent update. Check the referenced issue @miguelchico made, he explains in there. |
@miguelchico This has absolutely nothing to do with typings, and everthing to do with how you have structured you code.
function TestController(
$q: ng.IQService,
$http: ng.IHttpService,
$timeout: ng.ITimeoutService) { ... }
/**
* @param {ng.IQService} $q
* @param {ng.IHttpService} $http
* @param {ng.ITimeoutService} $timeout
*/
function TestController($q, $http, $timeout) { which reads the types right out of the .d.ts file and gives you intellisense as shown
/* @ngInject */
function TestController($q, $http, $timeout) { A couple of notes. I am using [email protected] in VSCode by settings "typescript.tsdk", I have a jsconfig.json file in my project with just an empty object It is also worth noting that the maintainer of ng-annotate is moving on, see olov/ng-annotate/issues/245. @bmontgom There are several extensions that support Typings and TSD in VSCode |
Here is the src https://github.com/aluanhaddad/salsa-ng-1x-example |
thank for your explanation @aluanhaddad, but my point is still there. If you check the issue I opened to vscode team, I explained there that for the same code I wrote here (I know @ngInject is not necessary at all for the example) before the TypeScript Salsa service the types of controllers parameter were automatically discovered. I know I can do the same writing type annotations in JSDoc, but it force me to write a lot of information that was not necessary before. You can try your example with a previous version of vscode (0.10.9) and you'll see that even without the JSDoc comments, the editor is able to detect the injected parameters in the controller. This issue is to ask for that behavior again. |
@miguelchico Sorry, I didn't read the VSCode issue. I have since done so and noticed the comment
I imagine they must have had a mapping somewhere that looked like |
@aluanhaddad Just for some more background. VS Code always used TypeScript to power JavaScript. In the past we used some source rewriting that translates JS to TS behind the scenes and then used TS to get Intellisense etc. As part of this translation we did the pragmatic mapping of $scope -> ng.I{Scope}Service in the generated JS code. Now that TS is supporting JS directly we have switched to this support and could remove the source code rewriting. |
I think the only solution to fix this issue, is to wait for #6508 and implement an angular1 plugin like I have done with ternjs https://github.com/angelozerr/angularjs-eclipse/wiki/Javascript-Features#completions |
@egamma thank you for the explanation and context, it is very enlightening. |
Given how injection work in Angular1, I do not think there is a way for the express that to the TypeScript type system other than hard coding the support in. We have avoided hard coding any behaviors for frameworks, and that has served us well in the past. A possible solution here is to add this support in a language service extension that users opt-into. the extension would do a pass over input files and add zero-length nodes for types (i.e. synthetic nodes that do not exist in the source), then pass that to the compiler. for instance More information about language service plugins can be found at https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin |
TypeScript Version: 1.8.10
Using the controller above (written in javascript) the type of injected parameters can't be infered.
Code
Expected behavior:
parameters $q, $http and $timeout well typed
Actual behavior:
parameters $q, $http and $timeout of type any
Check: microsoft/vscode#8163
The text was updated successfully, but these errors were encountered: