1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| enum Type { Strong, Week}
class Java { helloJava() { console.log('Hello Java') } }
class JavaScript { helloJavaScript() { console.log('Hello JavaScript') } }
function getLanguage(type: Type) { let lang = type === Type.Strong ? new Java() : new JavaScript() if (lang.helloJava){ lang.helloJava() } return lang }
getLanguage(Type.Strong)
|