You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeA=numbertypeB=stringtypeC=number|stringconstcc: C[]=[1,2,"a","b"]functionisNumber(a): a is A{returntypeofa==='number'}// OKconstdd=[]for(letn=0;n<cc.length;n++){constd=cc[n]if(typeofd==='number'){dd.push(d.toFixed())}}// OKconstee=[]for(letn=0;n<cc.length;n++){constd=cc[n]if(isNumber(d)){ee.push(d.toFixed())}}// NOT OK - property 'toFixed' does not exist on type 'number' | 'string'// (guard fails when using "cc[n]" instead of first assigning to "d")constff=[]for(letn=0;n<cc.length;n++){if(typeofcc[n]==='number'){ff.push(cc[n].toFixed())}}// NOT OK - property 'toFixed' does not exist on type 'number' | 'string'// (guard fails when guarding the inverse)constgg=[]for(letn=0;n<cc.length;n++){constd=cc[n]if(typeofd!=='number'){continue}gg.push(d.toFixed())}// NOT OK - property 'toFixed' does not exist on type 'number' | 'string'// (guard fails when used in a filter)// @see https://github.com/Microsoft/TypeScript/issues/7657consthh=cc.filter(isNumber).map(c=>c.toFixed())
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: