core
core copied to clipboard
Missing types in TranslatePipe
Hi folks,
First of all let me thank you for the awesome work you've accomplished here! It's really been a pleasure to use. Lately I updated an angular 9 project to perform extended checks when compiling.
# => tsconfig.json
...
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
Unfortunately ever since I am getting annoying warnings, namely:
Argument of type 'string | undefined' is not assignable to parameter of type 'string' component.html:12:13 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
<span>{{possiblyUndefinedVariable | translate}}</span>
Of course I could wrap the entire block in an *ngIf
but I feel that the pipes type should rather reflect that it may accept parameters of types other than string
.
In fact, the specs and current implementation are defined in a way that the logic returns early, if it hits a falsy/empty value.
Implementation: https://github.com/ngx-translate/core/blob/master/projects/ngx-translate/core/src/lib/translate.pipe.ts#L40-L43
Test: https://github.com/ngx-translate/core/blob/master/projects/ngx-translate/core/tests/translate.pipe.spec.ts#L164-L171
Am I doing something complete off the charts here, or is my idea of defining the query
parameter more accurate correct?
I would gladly provide a PR if this is the right direction.
+1