Skip to content

Conversation

@NeilRashbrook
Copy link
Contributor

This enables you to write .find((e): e is Derived => e instanceof Derived) and TypeScript will infer the type of the expression to be Derived instead of the type of the collection. (Similarly for the other methods.)

This enables you to write `.find((e): e is Derived => e instanceof Derived)` and TypeScript will infer the type of the expression to be `Derived` instead of the type of the collection. (Similarly for the other methods.)
@benbucksch
Copy link
Owner

Why would you not simply declare the collection to be Subtype (= Derived in your example)?

@NeilRashbrook
Copy link
Contributor Author

It contains object of multiple subtypes, but you happen to know that the one you're trying to find has a specific subtype.

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.

2 participants