From 3eaa006c6f0b33f05ee39aa413abcd2eb5e85e08 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 23 Nov 2023 11:47:36 +0000 Subject: [PATCH] test(compiler-cli): additional type-check transform tests for signal inputs (#53571) This commit adds additional type-check transform tests for signal inputs. These tests verify some of the problems with covariance, contravariance and bivariance that we were suspecting to be problematic if we would assign `InputSignal`'s directly to the type constructors. PR Close #53571 --- .../test/input_signal_diagnostics_spec.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/input_signal_diagnostics_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/test/input_signal_diagnostics_spec.ts index 2d23c217eee..50ebc638e2e 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/input_signal_diagnostics_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/input_signal_diagnostics_spec.ts @@ -399,6 +399,79 @@ runInEachFileSystem(() => { `TestComponent.html(3, 63): Type 'number' is not assignable to type 'null'.`, ], }, + // differing Write and ReadT + { + id: 'differing WriteT and ReadT, superset union, valid binding', + inputs: { + bla: { + type: 'InputSignal', + isSignal: true, + }, + }, + template: `
`, + expected: [], + }, + { + id: 'differing WriteT and ReadT, superset union, invalid binding', + inputs: { + bla: { + type: 'InputSignal', + isSignal: true, + }, + }, + template: `
`, + expected: [ + `TestComponent.html(1, 11): Type '2' is not assignable to type 'string | boolean'.`, + ], + }, + { + id: 'differing WriteT and ReadT, divergent, valid binding', + inputs: { + bla: { + type: 'InputSignal', + isSignal: true, + }, + }, + template: `
`, + expected: [], + }, + { + id: 'differing WriteT and ReadT, divergent, invalid binding', + inputs: { + bla: { + type: 'InputSignal', + isSignal: true, + }, + }, + template: `
`, + expected: [ + `TestComponent.html(1, 11): Type 'boolean' is not assignable to type 'string'.`, + ], + }, + { + id: 'differing WriteT and ReadT, generic ctor inference', + inputs: { + bla: { + type: 'InputSignal', + isSignal: true, + }, + }, + extraDirectiveMembers: [ + `tester: {t: T, blaValue: never} = null!`, + ], + directiveGenerics: '', + template: ` +
`, + component: `prop: HTMLElement = null!`, + expected: [ + // This verifies that the `ref.tester.t` is correctly inferred to be `HTMLElement`. + `TestComponent.html(3, 46): Type 'number' is not assignable to type 'HTMLElement'.`, + // This verifies that the `bla` input value is still a `string` when accessed. + `TestComponent.html(3, 59): Type 'string' is not assignable to type 'never'.`, + ], + }, + // TODO(devversion): inline constructor test ]; for (const c of bindingCases) {