LINQ .concat conflicts with native Typescript / Javascript .concat method
capnkts opened this issue ยท 7 comments
We just installed your linq-to-typescript package in our Angular application and we found that it overrides the native .concat method for Typescript / JavaScript. Is there any possibility you can either rename the LINQ .concat method to something other than .concat? If not, is there any way to set up the package to not override the native .concat method?
Another great option is if the LINQ methods are being extended to the specific object, when it's a string, it would help to return a string instead of an IEnumerable. The native .concat method for strings just takes two strings and returns a concatenated string. The linq-to-typescript package will return an IEnumerable, which breaks a lot of other packages that use the native .concat. That's the reason for even bothering you with this. Thank you!
I suggest not using initializeLinq
and instead importing and using from
- it will not pollute/override anything.
See the with wrappers section,
https://github.com/arogozine/LinqToTypeScript#with-wrappers
I will rename the conflicting method in the next release.
We liked your package since we didn't have to use wrappers and this is the only conflict with any other native method that we've seen. When will the next release come out? If you ever used the original LINQ-to-JavaScript in AngularJS, the LINQ methods were extended to any JavaScript array without any wrappers. So that's why we really liked your LINQ-to-Typescript package since you could do the same thing with the initializeLinq function. Renaming the conflicting method would make this package perfect.
Thanks so much for your response!
Per,
https://github.com/arogozine/LinqToTypeScript/blob/master/src/initializer/bindArray.ts
I might not be overriding the method at all. I don't recall how that code. Weird.
Try the following,
const test = [1, 2].concat([1, 2])
console.log(test instanceof Array)
If that returns true to you, try the following,
declare global {
interface Array<T> extends IEnumerable<T> {
concat(...items: Array<ReadonlyArray<T>>): ArrayEnumerable<T>;
concat(...items: Array<T | ReadonlyArray<T>>): ArrayEnumerable<T>;
concat(items: IEnumerable<T>): IEnumerable<T>;
}
interface Uint8Array extends IEnumerable<number> { }
interface Uint8ClampedArray extends IEnumerable<number> { }
interface Uint16Array extends IEnumerable<number> { }
interface Uint32Array extends IEnumerable<number> { }
interface Int8Array extends IEnumerable<number> { }
interface Int16Array extends IEnumerable<number> { }
interface Int32Array extends IEnumerable<number> { }
interface Float32Array extends IEnumerable<number> { }
interface Float64Array extends IEnumerable<number> { }
interface Map<K, V> extends IEnumerable<[K, V]> { }
interface Set<T> extends IEnumerable<T> { }
interface String extends IEnumerable<string> { }
}
Note that the concat order has moved around.
I did try this, and the test returned true, so then I changed the declaration of 'global' to what you specified in your previous response. The issue is that a normal Typescript .concat returns a BasicEnumerable when it should just return a string if we're concatenating two strings together.
I've attached a few files so you can see what I'm seeing. The first is the error, and it only relates to the linq-to-typescript .concat method from what I can tell:
The second is the code example you had along with a normal string concatenation:
The third is the screenshot of the results of that test:
The fourth is the description of the native Typescript .concat method:
If you could rename it to something other than a native method in Typescript, I think that would fix the problem and allow the native .concat method to return a string when two strings are concatenated together. Right now, the LINQ .concat method returns a BasicEnumerable for two strings instead of just returning a concatenated string.
Thanks!
I renamed the method from concat
to concatenate
, see if it works for you,
LINQ to TypeScript 8.0 BETA
Update your globals like so
interface Array<T> extends IEnumerable<T> { }
BTW, if you'll let us know how to donate to you for the hard work on this package, please let us know.