jeudi 20 février 2020

How to avoid if-else multiple checks (spaghetti code) in typescript

General question: How to avoid if-else ugly code when you have to deal with multiple checks based on some string type?

Example: I have an object "Task" in TODO app, which can be of different types, e.g. simple checkbox, textarea, date, a combination of fields etc. For each type of a "Task", there is different logic on how to change the object before saving it.

How to leverage typescript and organize the code without if-else statements.

Aucun commentaire:

Enregistrer un commentaire