Using TypeScript version 2.4.2, compiled with the --target ES6
option has interesting results.
For example, when using this line of code:
var coins: { coin: number}[] = [1,1,1]
TypeScript throws an error:
Error TS2322: Type 'number[]' is not assignable to type '{ coin: number; }[]'
Surprisingly, when using this line:
var coins: { coin: number}[] = Array(3).fill(1)
The code compiles successfully without any errors.
This raises the question - is this a bug in TypeScript or is it actually intended behavior? And if so, why does TypeScript allow this kind of array declaration without performing type checking?