declare function f(fun: <T>(t: T) => void): void
f((t) => {
type T = typeof t
type IsStringArray = T[] extends string[] ? true : false // false
})
function g<T>(t: T) {
type IsStringArray = T extends string[] ? true : false // T extends string[] ? true : false
}
IsStringArray
is false
in the parameter of f
, while is T extends string[] ? true : false
in the body of g
.
What make the difference?
https://www.typescriptlang.org/play/?ssl=10&ssc=2&pln=1&pc=1#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIAoVUAueAHgBUA+AjMygSngF5r4A3HLYRsrngChEBOszbwA3oPiz4GAJ4AHBJVbzlIHInky5ilfACSAZwDKGGFlQBzAIIwYUBesoBtALrwQADwwhUYBN4E0trG094AH55GGQEMkQoCBMEAHo0pGTUwUEAX0Zc4kxcfBsqWnp4Jik9WQMEUwsrWwcnFxZq7z8AoJCw20iYy3j4ROz0zLVff0Dg0JaIr2G4hKyUkHygA
I expected two types are the same
m-shaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.