From 2aa6d6d616575ed6b5243ee6df97ca0346714745 Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Sat, 15 Apr 2023 20:51:07 +0200 Subject: [PATCH] refactor(compiler-cli): cleanup inferences (#49863) With the ts compiler updates these inferences have been fixed. PR Close #49863 --- .../src/ngtsc/annotations/common/src/di.ts | 3 +-- .../ngtsc/annotations/component/src/resources.ts | 14 ++------------ .../ngtsc/typecheck/diagnostics/src/diagnostic.ts | 3 +-- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/common/src/di.ts b/packages/compiler-cli/src/ngtsc/annotations/common/src/di.ts index 096a8bd1b1f..bb34a2108c6 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/common/src/di.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/common/src/di.ts @@ -143,9 +143,8 @@ export function validateConstructorDependencies( } else if (deps.deps !== null) { return deps.deps; } else { - // TODO(alxhub): this cast is necessary because the g3 typescript version doesn't narrow here. // There is at least one error. - const error = (deps as {errors: ConstructorDepError[]}).errors[0]; + const error = deps.errors[0]; throw createUnsuitableInjectionTokenError(clazz, error); } } diff --git a/packages/compiler-cli/src/ngtsc/annotations/component/src/resources.ts b/packages/compiler-cli/src/ngtsc/annotations/component/src/resources.ts index 96d5c169226..8d598b66f89 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/component/src/resources.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/component/src/resources.ts @@ -111,15 +111,7 @@ export type TemplateDeclaration = InlineTemplateDeclaration|ExternalTemplateDecl /** Determines the node to use for debugging purposes for the given TemplateDeclaration. */ export function getTemplateDeclarationNodeForError(declaration: TemplateDeclaration): ts.Node { - // TODO(zarend): Change this to if/else when that is compatible with g3. This uses a switch - // because if/else fails to compile on g3. That is because g3 compiles this in non-strict mode - // where type inference does not work correctly. - switch (declaration.isInline) { - case true: - return declaration.expression; - case false: - return declaration.templateUrlExpression; - } + return declaration.isInline ? declaration.expression : declaration.templateUrlExpression; } export interface ExtractTemplateOptions { @@ -199,9 +191,7 @@ export function extractTemplate( sourceMapping: { type: 'external', componentClass: node, - // TODO(alxhub): TS in g3 is unable to make this inference on its own, so cast it here - // until g3 is able to figure this out. - node: (template as ExternalTemplateDeclaration).templateUrlExpression, + node: template.templateUrlExpression, template: templateContent, templateUrl: template.resolvedTemplateUrl, }, diff --git a/packages/compiler-cli/src/ngtsc/typecheck/diagnostics/src/diagnostic.ts b/packages/compiler-cli/src/ngtsc/typecheck/diagnostics/src/diagnostic.ts index af34a62f66a..04059193bcc 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/diagnostics/src/diagnostic.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/diagnostics/src/diagnostic.ts @@ -61,10 +61,9 @@ export function makeTemplateDiagnostic( // For external temoplates, the HTML filename is used. const componentSf = mapping.componentClass.getSourceFile(); const componentName = mapping.componentClass.name.text; - // TODO(alxhub): remove cast when TS in g3 supports this narrowing. const fileName = mapping.type === 'indirect' ? `${componentSf.fileName} (${componentName} template)` : - (mapping as ExternalTemplateSourceMapping).templateUrl; + mapping.templateUrl; let relatedInformation: ts.DiagnosticRelatedInformation[] = []; if (relatedMessages !== undefined) {