jeudi 20 décembre 2018

How to check if boolean is passed as string?

So in below code if i pass ancillaryProductInd as boolean code works but when i pass as a string it does not work in my understanding below code code should only work when i pass "false" string value and throw error on boolean. Any idea what is the issue here ?

main.ts

request

    var rxInfos = 
         [{
                "ancillaryProductInd": "false",
                "indexID": "eyJrZXkiOiIEOHdpNUpNWmR3PT0ifQ=="
            }]


    function subQuestionsHandler(rxInfos, data) {
            const subQuestionArray = [];
            rxInfos.forEach((rxInfo) => {
                const subQuestion = { question: [] };
                if (rxInfo.ancillaryProductInd !== undefined && rxInfo.ancillaryProductInd === "false") {
                    subQuestion.question = data;
                    subQuestionArray.push(subQuestion);
                }
            });
            return subQuestionArray;
        }

subQuestionsHandler(rxInfos , [{some data}]);

Aucun commentaire:

Enregistrer un commentaire