Pipes with generic type parameters don't typecheck
Which @angular/* package(s) are the source of the bug?
language-service
Is this a regression?
No
Description
Lets say we have a pipe that returns a number:
@Pipe({
name: 'test'
})
export class TestPipe<T> implements PipeTransform {
transform(value: T): number {
return 1;
}
}
When we use it on input that expects a string it works fine without a type error:
@Component({
selector: 'app-foo'
})
export class FooComponent {
@Input() text: string;
}
<app-foo [text]="'bar' | test"></app-foo>
This should show a type error because the input expects a string and the pipe returns a number.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version)
No response
Anything else?
I'm using strictTemplates: true
Pipes with generic type parameters are not currently supported. In your case the T type parameter can be dropped in favor of using unknown where it's used.
Just got caught by this. Any technical reason or just a nice to have that no one has every tried to implement? Curious because it perhaps its reasonable to take on as a first time contributor?
It would require a different approach to how pipes are declared in the type-checker, specifically using a type constructor. A lot more details are in https://github.com/angular/angular/pull/40870#issuecomment-780882880. There's also this comment.