angular/packages/compiler/src
Paul Gschwendtner abdc7e4578 feat(compiler-cli): support type-checking for generic signal inputs (#53521)
This commit adds the last remaining piece for signal input
type-checking. Bound values to signal inputs are already checked
properly at this point, but inference of generic directive/component
types through their inputs is not implemented.

This commit fixes this. To achieve this, there are a couple of potential
solutions. The generics of a directive are inferred based on input
value expressions using a so-called type constructor. The constructor
looks something like this:

```
const _ctor = <T>(v: Pick<Dir<T>, 'input1', 'input2'>) => Dir<T>;

_ctor({input1: expr1, input2: expr2});
```

This works very well for non-signal inputs where the class member is
directly holding the input values. For signal inputs, this does NOT
work because the class member will actually hold the `InputSignal`
instance. There are a couple of solutions to this:

1. Calling `_ctor` with an `InputSignal<typeof value>`
2. Converting the `_ctor` input signal fields to their write types
   (unwrapping the input signals).

We've decided to go with the second option as TypeScript is very
sensitive with assignments and its checks. i.e. co-variance,
contravariance or bivariance. Semantically it makes more sense to unwrap
the input signal "write type" directly and "assign to it". This is safer
and conceptually also easier to follow. A type constructor continues to
only receive the "expresison values". This simplifies code as well.

It's worth noting that the unwrapping as per option 2 also comes at a
cost. We need to be able to generate imports in type constructors. This
was not possible until the previous commit because inline type constructors
did not have an associated type-check block `Environment` and we were
missing access to expression translation and correct import generation.

Overall, solution 2 is now implemented as works as expected. This commit
adds additional unit tests to ensure this.

PR Close #53521
2023-12-13 15:44:00 -08:00
..
compiler_util refactor(compiler): add support for advanced tracking expressions (#51618) 2023-09-05 14:19:18 +00:00
expression_parser fix(compiler): produce placeholder for blocks in i18n bundles (#52958) 2023-11-20 08:59:24 -08:00
i18n fix(compiler): produce placeholder for blocks in i18n bundles (#52958) 2023-11-20 08:59:24 -08:00
ml_parser fix(compiler): produce placeholder for blocks in i18n bundles (#52958) 2023-11-20 08:59:24 -08:00
output perf(compiler): further reduce bundle size using arrow functions (#52010) 2023-10-04 07:25:54 -07:00
render3 feat(compiler-cli): support type-checking for generic signal inputs (#53521) 2023-12-13 15:44:00 -08:00
schema fix(core): hardening attribute and property binding rules for <iframe> elements (#47964) 2022-11-09 00:47:56 -08:00
template/pipeline refactor(compiler): Support o.WrappedNodeExpr inside expression conversion (#53478) 2023-12-13 09:21:53 -08:00
template_parser fix(compiler): produce placeholder for blocks in i18n bundles (#52958) 2023-11-20 08:59:24 -08:00
assertions.ts refactor(compiler): remove unused assertion function (#44411) 2022-01-04 15:54:09 -08:00
chars.ts refactor(compiler): share isQuote() via chars.ts (#43129) 2021-08-16 13:07:23 -07:00
compiler.ts refactor(compiler): provide a private API to perform direct style encapsulation (#53363) 2023-12-08 14:29:18 -08:00
compiler_facade_interface.ts refactor(compiler): emit signal input info in d.ts and generate partial compilation output (#53521) 2023-12-13 15:44:00 -08:00
config.ts feat(core): Remove deprecated CompilerOptions.useJit andCompilerOptions.missingTranslation. (#49672) 2023-10-10 09:35:55 -07:00
constant_pool.ts perf(core): generate arrow functions for pure function calls (#51668) 2023-09-06 15:32:02 +00:00
core.ts refactor(compiler): introduce compiler infrastructure for input transforms (#50225) 2023-05-22 14:48:02 +00:00
injectable_compiler_2.ts perf(compiler): further reduce bundle size using arrow functions (#52010) 2023-10-04 07:25:54 -07:00
jit_compiler_facade.ts refactor(compiler): emit signal input info in d.ts and generate partial compilation output (#53521) 2023-12-13 15:44:00 -08:00
parse_util.ts refactor: replace deprecated String.prototype.substr() (#45397) 2022-03-24 11:48:09 -07:00
resource_loader.ts refactor(compiler): ensure compatibility with noImplicitOverride (#42512) 2021-07-12 13:11:14 -07:00
selector.ts feat(compiler): allow self-closing tags on custom elements (#48535) 2023-01-04 12:07:37 -08:00
shadow_css.ts fix(compiler): apply style on :host attributes in prod builds. (#49118) 2023-10-11 11:32:19 -07:00
style_url_resolver.ts refactor(compiler): make template preparser null-safe (#44411) 2022-01-04 15:54:10 -08:00
util.ts refactor(compiler): use globalThis for global (#50063) 2023-07-14 18:32:01 +00:00
version.ts docs: fix package name in version.ts files in different packages (#41208) 2021-05-10 10:26:34 -04:00