Skip to content

Commit

Permalink
test(compiler-cli): additional type-check transform tests for signal …
Browse files Browse the repository at this point in the history
…inputs (angular#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 angular#53571
  • Loading branch information
devversion authored and danieljancar committed Jan 26, 2024
1 parent 5bb8e20 commit 57d179d
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean, boolean|string>',
isSignal: true,
},
},
template: `<div dir bla="string value">`,
expected: [],
},
{
id: 'differing WriteT and ReadT, superset union, invalid binding',
inputs: {
bla: {
type: 'InputSignal<boolean, boolean|string>',
isSignal: true,
},
},
template: `<div dir [bla]="2">`,
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<boolean, string>',
isSignal: true,
},
},
template: `<div dir bla="works">`,
expected: [],
},
{
id: 'differing WriteT and ReadT, divergent, invalid binding',
inputs: {
bla: {
type: 'InputSignal<boolean, string>',
isSignal: true,
},
},
template: `<div dir [bla]="true">`,
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<string, T>',
isSignal: true,
},
},
extraDirectiveMembers: [
`tester: {t: T, blaValue: never} = null!`,
],
directiveGenerics: '<T>',
template: `
<div dir [bla]="prop" #ref="dir"
(click)="ref.tester = {t: 0, blaValue: ref.bla()}">`,
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) {
Expand Down

0 comments on commit 57d179d

Please sign in to comment.