refactor: use type guard instead of unnecessary or incorrect type assertions#659
refactor: use type guard instead of unnecessary or incorrect type assertions#659mgechev merged 1 commit intomgechev:masterfrom rafaelss95:refactor-type-guard
Conversation
| logger.error('Cannot parse the styles of', ((<any>metadata.controller || {}).name || {}).text, e); | ||
| const { | ||
| controller: { name } | ||
| } = metadata; |
There was a problem hiding this comment.
This needs defaults in order to guard the same way the original did. Not sure if intentional.
There was a problem hiding this comment.
The property controller always exists according to:
codelyzer/src/angular/metadata.ts
Lines 23 to 27 in da0f553
... and it makes sense, because once we instantiate a DirectiveMetadata, we pass all properties:
codelyzer/src/angular/metadataReader.ts
Lines 63 to 67 in da0f553
... now I'm curious on why we are using Object.assign instead of a trivial constructor. Thoughts?
Anyway, these "defaults" should have been changed in #631, but I really forgot about it. 😞
|
bump 👽 |
| private consumer: SourceMapConsumer; | ||
|
|
||
| constructor(sourceFile: ts.SourceFile, options: IOptions, protected codeWithMap: CodeWithSourceMap, protected basePosition: number) { | ||
| constructor(sourceFile: ts.SourceFile, options: IOptions, public codeWithMap: CodeWithSourceMap, protected basePosition: number) { |
There was a problem hiding this comment.
It was necessary because I've changed the type of context in trackByRule#35 from any to BasicTemplateAstVisitor (https://github.com/mgechev/codelyzer/pull/659/files#diff-26d9296d5e0a25d3fe6a9b174e67da35R35)... it gives an error with protected:
src/trackByFunctionRule.ts(44,30): error TS2446: Property 'codeWithMap' is protected and only accessible through an instance of class 'TrackByFunctionTemplateVisitor'.
| import { SourceMappingVisitor } from '../sourceMappingVisitor'; | ||
|
|
||
| const getExpressionDisplacement = (binding: any) => { | ||
| const getExpressionDisplacement = (binding: ast.TemplateAst) => { |
This:
PS: You can see that there are a lot more places that could be changed, but these or I can't replace, because changing them, breaks something or unfortunately it has to be any.