From 80b67e02b7d3f6f31b0042681dfd5a365cd628b3 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 4 Jul 2020 00:16:18 +0200 Subject: [PATCH] fix(compiler-cli): infer quote expressions as any type in type checker (#37917) "Quote expressions" are expressions that start with an identifier followed by a comma, allowing arbitrary syntax to follow. These kinds of expressions would throw a an error in the template type checker, which would make them hard to track down. As quote expressions are not generally used at all, the error would typically occur for URLs that would inadvertently occur in a binding: ```html ``` This commit lets such bindings be inferred as the `any` type. Fixes #36568 Resolves FW-2051 PR Close #37917 --- packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts | 4 ++-- .../src/ngtsc/typecheck/test/type_check_block_spec.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts index e068cecb87..81fb098be2 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts @@ -234,8 +234,8 @@ class AstTranslator implements AstVisitor { return node; } - visitQuote(ast: Quote): never { - throw new Error('Method not implemented.'); + visitQuote(ast: Quote): ts.Expression { + return NULL_AS_ANY; } visitSafeMethodCall(ast: SafeMethodCall): ts.Expression { diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts index e9586441c1..febe9c9e98 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts @@ -42,6 +42,11 @@ describe('type check blocks', () => { .toContain('(((ctx).a) ? ((ctx).b) : (((ctx).c) ? ((ctx).d) : ((ctx).e)))'); }); + it('should handle quote expressions as any type', () => { + const TEMPLATE = ``; + expect(tcb(TEMPLATE)).toContain('null as any'); + }); + it('should handle attribute values for directive inputs', () => { const TEMPLATE = `
`; const DIRECTIVES: TestDeclaration[] = [{