Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

TypeScript call the method in the catch block

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"}
}
}


question from:https://stackoverflow.com/questions/66058282/typescript-call-the-method-in-the-catch-block

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...