Я с трудом пытаясь понять это:машинопись Интерфейс массива Тип ошибки TS2411
There are two types of supported index types: string and number. It is possible to support both types of index, with the restriction that the type returned from the numeric index must be a subtype of the type returned from the string index.
While index signatures are a powerful way to describe the array and 'dictionary' pattern, they also enforce that all properties match their return type. In this example, the property does not match the more general index, and the type-checker gives an error:
interface Dictionary { [index: string]: string; length: number; // error, the type of 'length' is not a subtype of the indexer }
Источник: TypeScript Handbook's interface
Я попытался 4 случая, но до сих пор не может понять, что происходит. Кто-нибудь объяснит, почему только [index: string]: string;
будет иметь ошибку TS2411?
Другой случай:
Вы пропустили один 'codio @ compact-guide'. Я не вижу причин, чтобы скрыть это в любом случае – basarat
пропустить два точно ..... –
Nice. Скрытие это заставило меня хотеть узнать больше :) – basarat