mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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
This commit is contained in:
parent
1c63eddb7c
commit
3eaa006c6f
1 changed files with 73 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue