Skip to content

type guard narrowing to a type with type with any in type parameters replaces any with unknown #57892

Description

🔎 Search Terms

type guard parameter any unknown

🕗 Version & Regression Information

  • This changed between versions 4.9.6 and 5.0.4

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240321#code/JYOwLgpgTgZghgYwgAgEIHsAeAeAKgPmQG8AoZc5ANzgBsBXCALmVxIF8SSY6QExh0IZMADOGHAQAUAIyzMeAaxDoA7iACUzWZmEi0WPIVIVkUCGDpQhYKA3acEgkWGQg6AW2nRxzcdkXKaoQAvMTU9EwAjBwkwDDIkqJ+bp7Q+JIpXlDi6urEZBSZ3lgAdOF2JgD0lSYmAHoA-PZxCUkGcCAAnulF2Vi5+Sa94mW0FRTVtRSN7EA

💻 Code

interfaceBox<T>{value: T}functionisBox<T>(box: unknown): box is Box<T>{returntrue}constnumberBox: Box<unknown>={value:1}if(isBox<number>(numberBox)){numberBox.value// ^?}if(isBox<any>(numberBox)){numberBox.value// ^?}

🙁 Actual behavior

if(isBox<any>(numberBox)){numberBox.value// ^? (property) Box<unknown>.value: unknown}

🙂 Expected behavior

if(isBox<any>(numberBox)){numberBox.value// ^? (property) Box<any>.value: any}

Additional information about the issue

Maybe caused by #52282 which also caused #53178

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions