8000 User defined type guard function and type any · Issue #5930 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
User defined type guard function and type any #5930
Closed
@Strate

Description

@Strate

Hi all!

interface A {
    prop: string
}

function isA(arg: any): arg is A {
    return "prop" in arg;
}

function handle(arg: any) {
    if (isA(arg)) {
        let b = arg.nonExistsProp; // no compile error here
    }
}

Why there is no compile error while acessing nonExistsProp? Is it by design and guard function only works with union types? Can't find some sort of specs, please, help me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0