forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler-cli): initial type-checking for signal inputs (angu…
…lar#53521) This commit introduces the initial type-checking for signal inputs. To enable type-checking od signal inputs, there are a couple of tricks needed. It's not trivial as it would look like at first glance. Initial attempts could have been to generate additional statements in type-checking blocks for signal inputs to simply call a method like `InputSignal#applyNewValue`. This would seem natural, as it would match what will happen at runtime, but this would break the language-service auto completion in a highly subtle way. Consider the case where multiple directives match the same input. Consider the directives have some overlap in accepted input values, but they also have distinct diverging values, like: ```ts class DirA { value = input<'apple'|'shared'>(); } class DirB { value = input<'orange'|'shared'>(); } ``` In such cases, auto completion for the binding expression should suggest the following values: `apple`, `shared`, `orange` and `undefined`. The language service achieves this by getting completions in the type-check block where the user expression would live. This BREAKS if we'd have multiple places where the expression from the user is used. Two different places, or more, surface additional problems with diagnostic collection. Previously diagnostics would surface the union type of allowed values, but with multiple places, we'd have to work with potentially 1+ diagnostics. This is non-ideal. Another important consideration is test coverage. It might sound problematic to consider the existing test infrastructure as relevant, but in practice, we have thousands of diagnostic type check block tests that would greatly benefit if the general emit structure would still match conceptually. This is another bonus argument on why changing the way inputs are applied is probably an option we should consider as a last resort. Ultimately, there is a good solution where we unwrap directive signal inputs, based on metadata, and access a brand type field on the `InputSignal`. This ensures auto-completion continues to work as is, and also the structure of type check blocks doesn't change conceptually. In future commits we also need to handle type-inference for generic signal inputs. Note: Another alternative considered, in terms of using metadata or not. We could have type helpers to unwrap signal inputs using type helpers like: `T extends InputSignal<any, WriteT> ? WriteT : T`. This would allow us to drop the input signal metadata dependency, but in reality, this has a few issues: - users might have `@Input`'s passing around `InputSignal`'s. This is unlikely, but shows that the solution would not be fully correct. - we need the metadata regardless, as we plan on accessing it at runtime as well, to distinguish between signal inputs and normal inputs when applying new values. This was not clear when this option was considered initially. PR Close angular#53521
- Loading branch information
1 parent
9bb3467
commit 19b0674
Showing
7 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters