How to assign string | undefined to string in TypeScript?

前端 未结 2 1142
醉梦人生
醉梦人生 2021-01-11 10:08

I want to assign a variable, which is string | undefined, to a string variable, as you see here:

private selectedSerialForReplace(): string | undefined {
            


        
2条回答
  •  孤城傲影
    2021-01-11 10:25

    If you are sure that serial could not be undefined you can use the ! post-fix operator

    luminaireReplaceLuminaire({serial: this.selectedSerialForReplace()!, newserial: response.output});
    

提交回复
热议问题