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

possibly 'undefined'. emitted after Boolean constructor check in Visual Studio #58485

Closed
kdevay opened this issue May 9, 2024 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@kdevay
Copy link

kdevay commented May 9, 2024

🔎 Search Terms

  • possibly 'undefined'
  • visual studio code
  • VS code
  • Boolean wrapper not supported
  • Boolean constructor not supported

🕗 Version & Regression Information

  • This is the behavior in TS Version 5.4.3, and I reviewed the FAQ for entries about undefined values after a boolean check

⏯ Playground Link

https://replit.com/join/cwiubczice-kdevay

💻 Code

interface Message {
  text: string;
  isBot: boolean;
}

interface ConversationProps {
  messages?: Message[];
}

const Conversation: React.FC<ConversationProps> = ({ messages }) => {
  return (
    <div
      id="conversation"
      className="flex flex-col gap-2 h-conversation overflow-y-scroll text-white"
    >
      {Boolean(messages && messages.length) &&
        messages.map((message, index) => (
          <div
            key={index}
            className="flex flex-row w-full"
          >
            <div>
              `${message.isBot ? '🤖' : 'you'}: ${message.text}`
            </div>
          </div>
        ))}
    </div>
  );
};

export default Conversation;

🙁 Actual behavior

I am seeing a red squiggle on messages.map stating that it is possibly undefined
Screenshot 2024-05-09 at 9 33 01 AM

🙂 Expected behavior

I should not see any error, because I performed this check: Boolean(messages && messages.length) .

I do not see an error message when I add the check without the Boolean constructor, like

      {(messages && messages.length) &&
        messages.map((message, index) => (

Additional information about the issue

TypeScript
Version 5.4.3

Visual Studio Code
Version: 1.89.0 (Universal)
Commit: b58957e67ee1e712cebf466b995adf4c5307b2bd
Date: 2024-05-01T02:10:10.196Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.4.0

My Machine
Model: Macbook pro
Chip: Apple M2
OS: Sonoma 14.4

@fatcerberus
Copy link

More or less the same as #16655

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 9, 2024
@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 May 12, 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

4 participants