Cast object to interface in TypeScript
There’s no casting in javascript, so you cannot throw if “casting fails”.Typescript supports casting but that’s only for compilation time, and you can do it like this: You can check at runtime if the value is valid and if not throw an error, i.e.: Edit As @huyz pointed out, there’s no need for the type assertion because isToDoDto is … Read more