You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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';functionprintNiceList(listOfStrings: List<string>): void{console.log(listOfStrings.pop().join(', ')+', and '+listOfStrings.last());}varcountries=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> ?
The text was updated successfully, but these errors were encountered:
You can not change the type signature of printNiceList because it calls pop. You would get an error of error TS2339 Property 'pop' does not exist on type 'IndexedIterable<string>'.
I am not sure what you mean when you say that rest() does not return a list as the return type of it certainly behaves like a list by having the pop method and satisfying List.isList (as one would expect).
As far as I can see Immutable's logic is solid, it is only the TS type definition that is lacking as it is indication a more generic return type (and that too is only a small cast inconvenience).
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.
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 isList<Blah>
vsIterable<number, string>
?The text was updated successfully, but these errors were encountered: