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

QuickInfo for ElementAccessExpression show original type when its type should be narrowed. #40013

Open
ShuiRuTian opened this issue Aug 12, 2020 · 0 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@ShuiRuTian
Copy link
Contributor

ShuiRuTian commented Aug 12, 2020

TypeScript Version: 4.0 beta

Search Terms:

Code

type Tmp = { i1: string | null };

function f2(t: Tmp) {
    if (typeof t.i1 === "string") {
        const tmp = t.i1;
        tmp;  // string
        t.i1;//string
    }
}


function f21(t: Tmp) {
    if (typeof t.i1 === "string") {
        const tmp = t["i1"];
        tmp;  // string
        t["i1"]; // string|null
    }
}

function f22(t: Tmp) {
    if (typeof t["i1"] === "string") {
        const tmp = t.i1;
        tmp;  // string
        t.i1;//string
    }
}

function f12(t: Tmp) {
    if (typeof t["i1"] === "string") {
        const tmp = t["i1"];
        tmp;  // string
        t["i1"];// string|null
    }
}

Expected behavior:
The quickinfo for ElementAccessExpression should also be "string"

Actual behavior:
It shows not narrowed type.

Playground Link:
https://www.typescriptlang.org/play?#code/C4TwDgpgBAKgtmKBeKBvKBLAjALigZ2ACcMA7AcygB8pSBXAGwagF8BuAWAChuAzO0gGNgGAPakovAEwAKYHnhgAlGm5RMvKHPARRm4ADpsyJCgBEhEhTMrUa9VEPY2AeheWy5ey24+e--iERcUkpLDkFBFt7DE1tSD1HIywTcw9raK4HRwBtM2wzAF02KDcCYk8qeiZvX24+AWExCWlZeVgo1SyNLVAE-TyCwtSoCwqMruynLFd3ca9uvz8GoObJLDbI5Ume+N0B-KwikbGrchsd9WBBo+Ky9PIqxgZarhYgA

Related Issues:

@ShuiRuTian ShuiRuTian changed the title QuickInfo for ElementAccessExpression does not show correctly if its type is narrowed. QuickInfo for ElementAccessExpression show original type when its type should be narrowed. Aug 12, 2020
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 17, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
2 participants