Skip to content

Conditional type evaluation not deferred when it depends on an implicitly-present type parameter #59450

@m-shaka

Description

@m-shaka

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

I'm not sure if it's a bug, but it seems like it's inconsistency of generic type.

declare function f(fun: <T>(t: T) => void): void
f((t) => {
    type T = typeof t

    type IsAny = T extends any ? true: false // deferred
    type IsAnyArray = T[] extends any[] ? true: false // return true

    type IsString = T extends string ? true : false // deferred
    type IsStringArray = T[] extends string[] ? true : false // return false
})

function g<T>(t: T) {
    type IsAny = T extends any ? true: false // deferred
    type IsAnyArray = T[] extends any[] ? true: false // return true

    type IsString = T extends string ? true : false // deferred
    type IsStringArray = T[] extends string[] ? true : false // deferred
}

I expected IsStringArray is deferred in the function passed to f like the. body of g, but evaluated as false

TS version: 5.5.3
Reproduction code: playground

(First I raised a question on stackoverflow, but now I think this question is more suitable here https://stackoverflow.com/questions/78801369/strange-behavior-of-generic-types-in-typescript)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions