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

assertion signature with primitive union: resulting type too narrow #36574

Closed
NaridaL opened this issue Feb 2, 2020 · 2 comments
Closed

assertion signature with primitive union: resulting type too narrow #36574

NaridaL opened this issue Feb 2, 2020 · 2 comments

Comments

@NaridaL
Copy link
Contributor

NaridaL commented Feb 2, 2020

TypeScript Version: 3.7.5, 3.8.0-dev.20200201

Search Terms:
assertion signature

Code

interface Foo {
    action(): void
    bar?: string
}

declare function assertFooBar(foo: any): asserts foo is ((Foo & { bar: string })|true)

declare const x: Foo | true
assertFooBar(x)

const y = x

Expected behavior:
y has type (Foo & { bar: string }) | true

Actual behavior:
y has type true.

Playground Link:
https://www.typescriptlang.org/play/?ts=3.8.0-dev.20200201&ssl=11&ssc=12&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChkHKJjDogAUAlAFzIBu6wAJvoQEZxQD8tAzmFFABzXAF9cuJhAQAbTihgBXEAhJkivXtDAZ0AIU7kYmWnBABPGhq1QwvZMazB75cruQAyHMg5Q+A4WRRSgAfAUUISgkpWXlkBDJ+ZAAPWncQ5HCIXDhNbV0DKHJkqNwEkCTzZABeFIkwcwAHFAAVGuRXN0xPb19-QRAhIMpkDKzKEa8urDGoCNKG5uQADXbdAHVgMAALQoAedMy5iAA+ZHqmlA2t3c49lrPatohkyBAme3cuNG6vbB9OP1AqJkLQWrhFldMJsdoUAIIWNbQm77MzmE64IA
Related Issues:

@RyanCavanaugh
Copy link
Member

Duplicate of #35953

@RyanCavanaugh RyanCavanaugh marked this as a duplicate of #35953 Feb 3, 2020
@NaridaL
Copy link
Contributor Author

NaridaL commented Feb 3, 2020

@RyanCavanaugh Yeah, I was half expecting this to be by design due to some type system subtlety. Thanks in any case.

@NaridaL NaridaL closed this as completed Feb 3, 2020
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