Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

type predicate #71

Open
sehyunchung opened this issue Jan 11, 2021 · 0 comments
Open

type predicate #71

sehyunchung opened this issue Jan 11, 2021 · 0 comments

Comments

@sehyunchung
Copy link
Owner

sehyunchung commented Jan 11, 2021

interface Article {
   title: string;
   body: string;
}

function isArticle(body: unknown): body is Article {
  let b = body as Article;
  return !!b && typeof b.body === 'string' && typeof b.title === 'string';
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant