angular - typescript checking using type guards -
i have method launches modalwindow takes element input (using $event.target) or number. trying perform check on type of input check treats element number if it's not. whether or not element number console.log outputted , else never runs.
launchmodal(element: number | any) { if (<number>element) { console.log('ele num', element); } else { const elementid = (event.target element).id; const elementidarray = string(elementid).split('-'); this.currentrow = parseint(elementidarray[2], 10); } this.loadequipmentfullrowdatarequest(this.currentrow); }
i following documentation advanced types @ official site
in typescript type system compile time only, in runtime code transpiled javascript , type information lost.
when if (<number>element)
cast doesn't anything, allows write code refers element
number (here aren't doing element
it's meaningless).
in order check if value got number have use javascript methods:
if(typeof(element) === 'number')
Comments
Post a Comment