Closed
Description
I have started using immutable.js within a TypeScript (1.5.3) project and it is working great save for one small annoyance.
Please excuse me if this has already been asked before or if there is something obvious that I am missing.
import { List } from 'immutable';
function printNiceList(listOfStrings: List<string>): void {
console.log(listOfStrings.pop().join(', ') + ', and ' + listOfStrings.last());
}
var countries = List(['USA', 'UK', 'Ukraine', 'Uzbekistan']);
// This works nicely:
printNiceList(countries);
// This does not pass the type check:
printNiceList(countries.rest());
// TSC errors with:
// error TS2345 Argument of type 'Iterable<number, string>' is not assignable to parameter of type 'List<string>'.
// > TS2324 Property 'set' is missing in type 'Iterable<number, string>'.
// The type needs to be explicit to get it to work:
printNiceList(<List<string>>countries.rest());
// Same issue with all inherited methods like: slice, splice, skip, concat, e.t.c
Since I work with List<Blah>
a lot I end up having to insert <List<Blah>>
all over the code which is a little annoying.
Would it be possible to redefine the inherited method types in the .d.ts
file so that these methods' return type is List<Blah>
vs Iterable<number, string>
?