Skip to content

Conversation

@jamashita
Copy link
Contributor

close #1016

@jamashita jamashita requested a review from Copilot October 24, 2025 11:48
@jamashita jamashita self-assigned this Oct 24, 2025
@vercel
Copy link

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
book Ready Ready Preview Comment Oct 24, 2025 11:49am

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds documentation for using switch (true) for type narrowing in TypeScript and removes an outdated note about TypeScript version requirements for type guard variable assignment.

  • Adds comprehensive section explaining switch (true) pattern for type narrowing
  • Removes note about TypeScript 4.4 version requirement for variable type guards
  • Includes examples with typeof, instanceof, and user-defined type guard functions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +248 to +254
return true;
};
const isBroccoli = (value: unknown): value is Broccoli => {
return true;
};
const isUser = (value: unknown): value is User => {
return true;
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type guard functions always return true which is misleading for documentation purposes. These should contain actual type checking logic (e.g., checking for the existence of properties like 'panda' in value) to demonstrate proper implementation of user-defined type guards.

Suggested change
return true;
};
const isBroccoli = (value: unknown): value is Broccoli => {
return true;
};
const isUser = (value: unknown): value is User => {
return true;
return typeof value === "object" && value !== null && "panda" in value;
};
const isBroccoli = (value: unknown): value is Broccoli => {
return typeof value === "object" && value !== null && "broccoli" in value;
};
const isUser = (value: unknown): value is User => {
return typeof value === "object" && value !== null && "name" in value;

Copilot uses AI. Check for mistakes.
@jamashita jamashita merged commit e56feb7 into master Oct 24, 2025
9 checks passed
@jamashita jamashita deleted the feature/1018 branch October 24, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript5.3で追加されたswitch (true)について記事を書きませんか?

2 participants