How to fix Assertion signature required for type narrowing in TypeScript | DevErrors