Skip to content
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

Type guard does not handle object properties #7655

Closed
Strate opened this issue Mar 23, 2016 · 1 comment
Closed

Type guard does not handle object properties #7655

Strate opened this issue Mar 23, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@Strate
Copy link

Strate commented Mar 23, 2016

TypeScript Version:

actual version on http://www.typescriptlang.org/Playground

Code

// A self-contained demonstration of the problem follows...
interface Props {
    options: {
        name: string | boolean
    }
}

let v: Props

if (typeof v.options.name === "string") {
    v.options.name.indexOf("123")
}

Expected behavior:
No error

Actual behavior:
Error: Property "indexOf" does not exist on type "string | boolean"

@yortus
Copy link
Contributor

yortus commented Mar 23, 2016

Yet another duplicate of #3812. This issue is getting really popular. See also this comment.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 23, 2016
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants