Objective is to log which text implementation is failing.
instanceof is on working for me in typescript(https://github.com/microsoft/TypeScript/issues/22585).
class textingBold extend text{ toTest(){} //toString() } class textingWithItalic extend text{ toTest(){} //toString() } ----- texts = [new textingWithItalic(), new textingBold()] for(const text of texts){ try{ text.toTest() //assume will result in the error for textingBlod } catch(e){ console.log('failed for '+ findInstanceOf(text)//text.toString()) } findInstanceOf(text: texter){ if (text instanceof textingBold){ return "textingBold"} if (text instanceof textingWithItalic){ return "textingWithItalic"} } }
2.1m questions
2.1m answers
60 comments
57.0k users