arogozine / LinqToTypeScript

LINQ to TypeScript
https://arogozine.github.io/linqtotypescript/
MIT License
139 stars 18 forks source link

max() on empty sequence from array throws #17

Closed vgpro54321 closed 2 years ago

vgpro54321 commented 2 years ago

Hello Guys,

IEnumerable<>.max() function in .NET returns null when sequence is empty (semantics maximum is unknown). LinqToTypeScript throws an error. Is this by design?

vgpro54321 commented 2 years ago

Anybody alive?

arogozine commented 2 years ago

By the design.

See here, https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.max?view=net-6.0#system-linq-enumerable-max(system-collections-generic-ienumerable((system-int32)))

under exceptions, It throws InvalidOperationException if 'source contains no elements'

Only outlier to that are nullable numeric types - which would be number | null or similar in TS, I suppose. The library only supports max(this: IEnumerable<number>): number and TSC should error out if you pass anything else in sctrict mode.

vgpro54321 commented 2 years ago

Make sense, thank you!