How to fix Cannot narrow type with instanceof for built-in types in TypeScript | DevErrors