Skip to content
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

Type Inference in Array callback is confusing #58776

Closed
sillysillyc opened this issue Jun 5, 2024 · 2 comments
Closed

Type Inference in Array callback is confusing #58776

sillysillyc opened this issue Jun 5, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@sillysillyc
Copy link

why ts would assume the condition in filter callback will never reach and mainChannel is always null

interface IMultiLensChannelCfg {
  main?: boolean
}

declare const channels: IMultiLensChannelCfg[]

let mainChannel: IMultiLensChannelCfg | null = null;

const secondaryChannels = channels.filter((e) => {
  if (!e.main) {
    return true;
  }
  mainChannel = e;
  return false;
});

 const mChannel = mainChannel;
 return (
      <>
        {mainChannel !== null && <web-component  channelId={mainChannel.id} />}
      <>
);
@sillysillyc sillysillyc added the Duplicate An existing issue was already created label Jun 5, 2024
@fatcerberus
Copy link

The text of the template you used to post this issue explained why this happens. Duplicate of #9998

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants