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

Integration with AngularJS - Compile AngularJS bindings in HTML files #369

Closed
vitalybe opened this issue Aug 6, 2014 · 9 comments
Closed
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@vitalybe
Copy link

vitalybe commented Aug 6, 2014

Consider the following code in an HTML file:

<div ng-controller="HomeController as home">
    {{home.property1}}
</div>

Since we know that "home" is an instance of HomeController, it would be great if TypeScript could compile that and throw a compilation error if "property1" doesn't exist in its definition.

@basarat
Copy link
Contributor

basarat commented Aug 6, 2014

Will be closed as not a part of the Design goals.

But I'd like to hear any community work.

@RyanCavanaugh
Copy link
Member

What basarat said. We're not an HTML compiler, but it would be cool to see someone write an HTML validator that used TypeScript files as a reference.

@Gambero81
Copy link

It will be a killer feature to implement! type check will be finally complete! actually parsing only .ts and no html leave code not really safe..

@basarat
Copy link
Contributor

basarat commented Oct 16, 2015

There is JSX support baked into TypeScript ... and I recommend looking into that 🌹 Quick rundown

@Gambero81
Copy link

i'm trying to implement type check in html angular bindings,
i can parse html with HtmlAgilityPack library and locate all angular bindings, now next step is to compile this bindings with typescript.
basarat in a stackoverflow post (http://stackoverflow.com/questions/25140029/use-typescript-in-angularjs-to-check-the-interpolation-binding-in-html) you suggest to use Typescript language service, do you have any suggestion how to use it? i only need to compile typescript code that i have extrapolated from html...
Thanks

@basarat
Copy link
Contributor

basarat commented Oct 26, 2015

you suggest to use Typescript language service, do you have any suggestion how to use it

I imagine something like pseudo ts files passed to the language as input and then asking the language service questions about the file (e.g. errors, completions) etc.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 27, 2015

also see #5151 for related discussion.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 27, 2015

@Gambero81 would be interested to see how this work proceeds; would appreciate it if you can share your progress.

@emmanueltouzery
Copy link

I wrote a project to handle this issue specifically for angular1 views. It uses the typescript compiler API to parse the javascript and typescript code, htmlparser2 to parse the views, and the parsimmon parser combinator library to parse angular expressions (such as "for .. in .. track by ..").

It then generates "viewtest" files, combining code from views and controllers, which then get type checked by the compiler at the same time as normal typescript files. It also allows the user to specify custom angular directives & filters to have them also type-checked.

Obviously it does not support everything possible with angular1, by far, as the scope is huge, but we use it on a real-size project at work, and tested it on another real-size one too.

You can find the project there:
https://github.com/emmanueltouzery/ng-typeview

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision 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

6 participants