[Idea] angular 1 template type checking with TypeScript
See original GitHub issueWouldn’t it be super useful if we could do type checking on template code in angular 1?
Quick research shows I’m not the only one having that thought: https://github.com/Microsoft/TypeScript/issues/5151 https://github.com/Microsoft/TypeScript/issues/369 https://github.com/thorn0/babel-plugin-transform-ng1-jsx
I’m bringing this here because this project plans to have or already has a template parser and is having the @Input()
and @Output()
decorators which define the API of a component.
So right now I’m just having this initial thought and would like to discuss it with the community. If there are already other projects that are better suited as a “starting point” for this than please share them here.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Template type checking - Angular
Just as TypeScript catches type errors in your code, Angular checks the expressions and bindings within the templates of your application and can...
Read more >Support strict template type checking in Angular ... - YouTrack
It's a pity that idea/webstorm only raises errors in inline templates. Correcting this will make it a lot easier for people to migrate...
Read more >WebStorm: Angular template type checking - Stack Overflow
Angular template checking is performed by the angular compiler. If you want type safe templates powered by just TypeScript, ...
Read more >Type-checking templates in Angular View Engine and Ivy
To be more precise, Angular creates Type Check Blocks (TCBs) based on the component template. Basically, a Type Check Block is a block...
Read more >Angular Template Type Checking - JavaScript in Plain English
Now, you might not all be aware of this, but Angular converts your templates into TypeScript code, whether those are separate HTML files...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just as a heads up: I’m working on this in my spare time. Got template-to-code transpiler basically working but did rely on TSLint as a kind of “runner” for it. This won’t work in the long run because of its “single-file-scope” but was enough to get going and do experiments.
Also there are lots of special-cases down the road that need to be solved but I will publish what I have on github as soon as it can be applied to a project with the complexity level of a TODO-app 😉
EDIT: After refactoring a codebase of >150 components I wish it would be already working!
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