Skip to content

Bug: Angular 12 full strict mode optional key pipe error #488

@eggp

Description

@eggp

Current behavior

In Angular 12 full strict mode, I get an error with a conditional key.
Angular 12 tsconfig: https://github.com/eggp/translocoNG12StrictPipeError/blob/master/apps/test/tsconfig.json#L16
Error:

Error: apps/test/src/app/app.component.html:1:8 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string | null'.
  Type 'undefined' is not assignable to type 'string | null'.

1 <div>{{options1?.some | transloco}}</div>
         ~~~~~~~~~~~~~~

  apps/test/src/app/app.component.ts:6:16
    6   templateUrl: './app.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component AppComponent.

Expected behavior

Accept undefined value as pipe key value.
Please add undefined to key type def. => https://github.com/ngneat/transloco/blob/faa58a5a0b73595173e3b5a640e4157d8ec50428/projects/ngneat/transloco/src/lib/transloco.pipe.ts#L35
Correct:

transform(key: string | null | undefined, params?: HashMap | undefined, inlineLang?: string | undefined): string {

Minimal reproduction of the problem with instructions

https://github.com/eggp/translocoNG12StrictPipeError

Environment

- Transloco version: 2.22.0
- Angular version: 12.X.X

Browser:

  • Chrome (desktop) version XX
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version XX
  • Safari (desktop) version XX
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions