-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert isPattern functions to TS user-defined type guards #1732
Comments
Actually, I guess for that to work, you'd also have to default every ent to include |
I think https://github.com/lolopinto/ent/compare/fix-1732?expand=1 is the best I can do (expand the PR to see manual changes) and then you'll have to call if you somehow have a different pattern or an ent which has that same shape, it'll pass and then fail in a different way... we can cheat and add a new field that's only unique to objects which have that pattern name which should heavily increase the odds of it returning the right thing |
What if, instead of const o = (obj as unknown as IWithAddress);
return 'addressId' in o && typeof o.addressId === 'string' || typeof o.addressId === 'number' || o.addressId === null; You kept the const o = (obj as unknown as IWithAddress);
return o.isWithAddress?.(); |
we can do that but it doesn't guarantee anything would still have this same issue
happy to make that change tho cos it's easier :) |
Yeah, I get that it's never possible to do this with 100% safety. Figured this was at least a little more direct about it though. |
Instead of simply doing
The
isSomePattern
can type the variable when it is called by changing the call signature.This would then allow you to do
someEnt?.isSomePattern() && someEnt.someID
without type errors.The text was updated successfully, but these errors were encountered: