0

anyone know how I can fix the following? I will have the error from vscode/webstorm Type 'undefined' is not assignable to type 'string' I have one customize function only accept one parameter with string type and I using if/else to filter out the parameter from undefined or string, but I still get the error Type 'undefined' is not assignable to type 'string' what is the best way for me to fix it?

function abc(value: string | number) {
    console.log(value)
}

abc(typeof x !== 'undefined' ? x : 'dummy string')
abc(0) // 0
abc(1) // 1
abc('') // ''
jacobcan118
  • 7,797
  • 12
  • 50
  • 95

0 Answers0