Skip to content

Inferred return type for function that return type assertion should be is [type] #14891

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mohsen1 opened this issue Mar 28, 2017 · 1 comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented Mar 28, 2017

TypeScript Version: 2.2.1

Code

function isString(x: any) {
    return typeof x === 'string';
}

Expected behavior:

Inferred type of foo is function isString(x: any): boolean

Actual behavior:

Inferred type should be function isString(x: any): x is string

@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2017

Related to #5101 (and #10734 tangentially)

I believe we discussed this before in the past, and concluded it was too complex to implement in the general case. doing it right needs to combine control-flow analysis with some sort of data flow analysis.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants