He revisado algunas respuestas diferentes de Stack Overflow que me llevaron a este punto. Hasta ahora he probado lo siguiente.
/** * Prints true, false or empty string * @param {boolean=} b */ test = (b = '') => { // Initialized type string not assignable to variable type boolean console.log(`b = "${b}"`) } /** * Prints true, false or empty string * @param {boolean=} b */ test = (b) => { // Initialized type string not assignable to variable type boolean if (typeof b !== 'boolean') b = '' console.log(`b = "${b}"`) }Tengo la sensación de que la respuesta correcta es suprimir la advertencia, pero espero que alguien más tenga una respuesta mejor.
En su código, el tipo puede ser una string o un boolean , por lo que necesita usar type union aquí:
/** * Prints true, false or empty string * @param {(boolean|string)=} b */ test = (b) => { // Initialized type string not assignable to variable type boolean if (typeof b !== 'boolean') b = '' console.log(`b = "${b}"`) }