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 predicate doesn't narrow parent object's type #43548

Closed
DetachHead opened this issue Apr 6, 2021 · 2 comments
Closed

type predicate doesn't narrow parent object's type #43548

DetachHead opened this issue Apr 6, 2021 · 2 comments

Comments

@DetachHead
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

predicate parent object type

πŸ•— Version & Regression Information

4.3.0-dev.20210406

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare function isBar(object: unknown): object is Bar

type Bar = {
    qux: number
}

type Foo<T extends Bar | {}> = {
    bar: T
    baz: number
}

declare const foo: Foo<Bar | {}>

declare function fooBar(value: Foo<Bar>): void

if (isBar(foo.bar)) {
    //foo.bar correctly narrowed to Bar:
    const a = foo.bar
    const b = foo.bar.qux

    //foo doesn't get narrowed and is still Foo<{} | Bar>, even though we know it's a Foo<Bar>
    fooBar(foo)
}

πŸ™ Actual behavior

foo.bar gets narrowed but foo doesn't

πŸ™‚ Expected behavior

foo is narrowed to Foo<Bar>

@MartinJohns
Copy link
Contributor

Duplicate of #42384. Used search terms: narrow parent

@DetachHead
Copy link
Contributor Author

oops, raised this twice because #43547 404'd on me right after i created it

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

No branches or pull requests

2 participants