-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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 TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue