'Why do the length properties of arrays and strings have different return types?

type GetLength2<T extends any[]> = T['length']
type a = GetLength2<[1]> // 1

type GetLength3<T extends string> = T['length']
type e = GetLength3<'abc'> // number

The length property of an array returns a specific value, but the length property of a string returns a number type, why?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source