镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Type guard intersection types - #9031

Merged
Anders Hejlsberg (ahejlsberg) merged 5 commits into
masterfrom
typeGuardIntersectionTypes
Jun 9, 2016
Merged

Anders Hejlsberg (ahejlsberg) merged 5 commits into
masterfrom
typeGuardIntersectionTypes

Conversation

@ahejlsberg

Copy link
Copy Markdown
Member

Fixes #8911.


// All winged beasts with legs
if (hasWings(beast)) {
if (beast.legs === 4) { // ERROR TS2339: Property 'legs' does not exist on type 'Winged'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comments are misleading now.

@mhegazy

Copy link
Copy Markdown
Contributor

👍

}
}

// Repro from #9011

@yortus Troy Gerwien (yortus) Jun 9, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be #9016

@yortus

Copy link
Copy Markdown
Contributor

This is a really great enhancement to type guards.

@yortus

Copy link
Copy Markdown
Contributor

IMO this is a major improvement to control flow based type inference that should probably be mentioned in the roadmap and in the upcoming 'what's new in TypeScript' for 2.0.

@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants