-
Notifications
You must be signed in to change notification settings - Fork 113
switch (true) による絞り込み
#1025
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
switch (true) による絞り込み
#1025
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this 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.
| return true; | ||
| }; | ||
| const isBroccoli = (value: unknown): value is Broccoli => { | ||
| return true; | ||
| }; | ||
| const isUser = (value: unknown): value is User => { | ||
| return true; |
Copilot
AI
Oct 24, 2025
There was a problem hiding this comment.
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.
| 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; |
close #1016