-
Notifications
You must be signed in to change notification settings - Fork 16
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
Interfere return type in .case doesn't work #20
Comments
You're right. Unfortunately this is a limitation of TypeScript that I don't see a way to work around in this circumstance. Unknown properties on object literals are not checked in the return value of functions which are given as arguments because TypeScript thinks its fine to accept a function which produces a return type which is a subtype of the desired type. A demo of this behavior: interface HasX {
x: number;
}
function getHasX(): HasX {
// Extra properties are errors.
return { x: 1, y: 2 };
}
function callGetHasX(f: () => HasX) {
f();
}
// No error here.
callGetHasX(() => ({ x: 1, y: 2 })); If this failure is enough of problem for you to not use this library, I understand. However, here are a few workarounds:
I'll think about this for a bit to see if I can come up with a better solution. If not, I'll make a note in the README about this. |
Hey, I just tried to use the library but unfortunately there is no type check in .case method for return value.
If I implement my reducer like this:
it will not allow me to return settings1 property because it doesn't exist in Execute model and it's fine however in your library it's completely fine to return any object.
The text was updated successfully, but these errors were encountered: