When I compile the following code (which to me seems incorrect because the type of the const and the type of the function () are different) no errors are produced:
export const yearsExtractor: (Period) => Year[] = (periods: Period[]): Year[] => periods && periods.length ? periods.map((period: Period) => period.year) : <Year[]>[];
When I compile the following code (which to me seems correct because the type of the const and the type of the function () match) an error is produced:
export const yearsExtractor: (Period[]) => Year[] = (periods: Period[]): Year[] => periods && periods.length ? periods.map((period: Period) => period.year) : <Year[]>[];
The difference being that the code that is not compiling is declaring the const as a function that accepts an array of Period objects (as opposed to a single Period object).
error
(Period[]) =>
no error
(Period) =>