You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
searched This comparison appears to be unintentional because the types ... have no overlap.ts(2367)
馃晽 Version & Regression Information
ts: 5.3.2
馃捇 Code
let acceptOrCancel: 'pending' | 'cancel' | 'pass' = 'pending';
// I use antd Modal.
Modal.confirm({
....
onOk: () => {
acceptOrCancel = 'pass';
},
onCancel: () => {
acceptOrCancel = 'cancel';
},
});
await waitForSomething({ func: () => acceptOrCancel !== 'pending' });
// This comparison appears to be unintentional because the types '"pending"' and '"cancel"' have no overlap.ts(2367)
if (acceptOrCancel === 'cancel') {
return {
status: false,
msg: 'user reject sign',
};
}
馃檨 Actual behavior
Modal.confirm will make a modal for user to ask if accept or not, It's async actually, but the function will return immediately. I have declare the type of the variable possible values and wait until the variable change, but Ts also report the error This comparison appears to be unintentional because the types '"pending"' and '"cancel"' have no overlap.ts(2367)
馃檪 Expected behavior
Ts don't report the error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
HuberTRoy
changed the title
Ts report a wrong comparison when the a variable may be changed async.
Ts report a wrong comparison when a variable may be changed async.
Mar 25, 2024
It's working as intended, yes. You can either close it yourself, or a TypeScript team member will mark this issue as duplicate and the bot will close it (or they close it directly).
A workaround is to use a type assertion to prevent the initial narrowing upon initialization: let acceptOrCancel = 'pending' as 'pending' | 'cancel' | 'pass'
Also, if possible (and here it clearly is), provide code example that can run on its own, and don't omit the Playground link. Your provided code does not compile as-is.
馃攷 Search Terms
searched
This comparison appears to be unintentional because the types ... have no overlap.ts(2367)
馃晽 Version & Regression Information
ts: 5.3.2
馃捇 Code
馃檨 Actual behavior
Modal.confirm
will make a modal for user to ask if accept or not, It's async actually, but the function will return immediately. I have declare the type of the variable possible values and wait until the variable change, but Ts also report the errorThis comparison appears to be unintentional because the types '"pending"' and '"cancel"' have no overlap.ts(2367)
馃檪 Expected behavior
Ts don't report the error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: