-
Notifications
You must be signed in to change notification settings - Fork 12.8k
satisfies operator breaks with callback on Partial object literals #55803
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
Comments
Functions arenβt contextually typed in their return type afaik so EPC doesnβt apply. Note that the excess property check is more of a built-in lint rule than a type check, so itβs intentionally not comprehensive. |
Simplified repro (Playground): type AuthState = {
isLoading: boolean;
isLoggedIn: boolean;
userToken: string | null;
};
type ActionFunction = (arg: any) => {
type: string;
payload: Partial<AuthState>;
};
const action1 = (({ userToken }: { userToken: string }) => ({
type: "fun",
payload: { userToken, isLoading: false, notAValidKey: 'Value' },
})) satisfies ActionFunction; // no EPC error
const action2: ActionFunction = ({ userToken }: { userToken: string }) => ({
type: "fun",
payload: { userToken, isLoading: false, notAValidKey: 'Value' },
}); // also no EPC error which I'm almost positive is a duplicate of like 10 other issues (latest I can find: #54661). tl;dr you shouldn't rely on the excess property check to enforce runtime invariants - you need #12936 for that. |
The closest thing to a canonical duplicate afaict is #7547 |
#241 is also relevant |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
"satisfies", "callback", "function"
π Version & Regression Information
β― Playground Link
Link to playground
π» Code
π Actual behavior
There is no error thrown on
payload
for the keynotAValidKey
as one would expect since this key isn't inside the Partial typeAuthState
. There is an error thrown fortype
with value22
so the callback typeActionFunction
isn't breaking the satisfies operator.π Expected behavior
This should throw an error on
restoreToken
in the aboveauthActions
const.The behaviour should mimic what happens when there is no callback in the object. For example as it errors here:
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: