angulartypescriptangular-pipedate-pipe

Argument type undefined is not assignable to parameter type string | undefined


im curios about an typescript (or maybe angular) error, that i dont fully unterstand. When using the date pipe with timezone parameter and no format:

{{ dateString | date:undefined:'+0430' }}

im getting the following error:

Argument type undefined is not assignable to parameter type string | undefined
Type undefined is not assignable to type string

According to other stackoverflow anwsers, passing undefined to skip an argument should be fine


Solution

  • I am not able to reproduce the issue on stackblitz!

    You could pass mediumDate which is the default formatwhen format parameter is falsy, which generates the same behaviour!

    Date Pipe Source Code

    Date Pipe Config Source Code

    I feel this is just a code editor error which can be ignored, but if you have to remove this error you can do this. Also note, if the default date mediumDate gets changed in the future, the code might not use the default format since we are hardcoding it!

    {{ dateString | date : 'mediumDate' : '+0430' }}
    

    Stackblitz Demo