Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
Confused about Type Predicate/Guard Safety
Post Body

In this tweet Cory recommends a User Defined Type Guard as a safer alternative to a type assertion/cast

e.g. instead of fish as Fish

function isFish(pet: Fish : Bird): pet is Fish {
    return (pet as Fish).swim !== undefined;
}

this does look 'safer' to me.. sure it's basically still doing the cast but it checks it has the swim method first, so..

why does matt say this is a "common mistake" (link to tweet)

What am i missing?

Author
Account Strength
90%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,224
Link Karma
81
Comment Karma
1,143
Profile updated: 1 day ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 months ago