Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
b181227
commit abdc7e4
Showing
10 changed files
with
226 additions
and
26 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
Oops, something went wrong.