found the code first in http://www.typescriptlang.org/docs/handbook/advanced-types.html#example-1
and then found this similar code in typescript codebase: https://github.com/microsoft/TypeScript/blob/master/tests/cases/conformance/types/conditional/conditionalTypes1.ts#L75
type KnockoutObservable<T> = { object: T };
type KnockoutObservableArray<T> = { array: T };
type KnockedOut<T> = T extends any[] ?
KnockoutObservableArray<T[number]> :
KnockoutObservable<T>;
type KnockedOutObj<T> = {
[P in keyof T]: KnockedOut<T[P]>;
}
what is the T[number] mean in the code?
in the Typescript Handbook example, it said
the element type of the array as T[number]
while test in the playground(just for testing), replace T[number]
with T
or T[any]
seems no different, but can not replace with T[string]
(why?).
the [number]
after T
seems not an index.