Skip to content

'typeof' doesn't return real type in switch control flow(type guard) #48471

@Messiahhh

Description

@Messiahhh

Bug Report

🔎 Search Terms

type guard、narrowing

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________

⏯ Playground Link

Playground link with relevant code

💻 Code

const value: number | string = 100;

function fn(): number | undefined {
    switch (typeof value) {
        case 'number':
            const v = typeof value;
            return v;
        default: 
            return 
    }
}

🙁 Actual behavior

the type of 'v' is not number

🙂 Expected behavior

the typeof of 'v' is number

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